Developer documentation for Ray

Client connections to the Shell

Most of the complexity of this code comes from the fact that we need to be able to connect to the Ray shell from an outside process (i.e. a Python process) that was started independently of the Ray shell. This is not supported in Mojo, they use fork to start child processes.

class ray::FileDescriptorSender

Send a file descriptor of a process to another process. This is needed because Mojo bootstraps the IPC communication between processes via a file handle (this makes sure no artifacts like actual files remain on the computer once the IPC has finished).

Public Functions

FileDescriptorSender(const std::string &address)

Initialize the FileDescriptorSender.

Parameters
  • address -

    Address of the socket that is used to send the file descriptor

bool Send(int file_descriptor, const std::string &payload)

Send the file descriptor over the socket.

Return
Bool that indicates if the sending was successful
Parameters
  • file_descriptor -

    The file descriptor that will be sent

  • payload -

    Additional payload that can be sent (< MAX_PAYLOAD_SIZE)

class ray::FileDescriptorReceiver

Receive a file descriptor from another process. This is needed because Mojo bootstraps the IPC communication between processes via a file handle (to make sure no artifacts like actual files remain on the computer once the IPC has finished).

Public Functions

int Receive(std::string &payload)

Receive file descriptor from the socket.

Return
The file descriptor that was sent or -1 if not successful.
Parameters
  • payload -

    The payload carried by this receive will be appended to this string

template <typename Service>
class shell::ServiceConnectionApp

The ServiceConnectionApp runs in a separate thread in the client and maintains a connection to the shell. It allows the client to connect synchronously to services, one service per ServiceConnectionApp. It allows the client to get InterfaceHandles to these services. These handles can be transfered to any client thread.

Inherits from ApplicationImplBase

Public Functions

ServiceConnectionApp(const std::string &service_name, std::condition_variable *notify_caller, mojo::InterfaceHandle<Service> *service_handle)

Construct a new ServiceConnectionApp that will connect to a service.

Parameters
  • service_name -

    The name of the service we want to connect to

  • notify_caller -

    Condition that will be triggered to notify the calling thread that the connection to the service is established

  • service_handle -

    A pointer to an InterfaceHandle that is owned by the calling thread