You can also use the underlay interfaces which MiniGUI uses to create your own UNIX domain socket.
Example:
#define LISTEN_SOCKET "/var/tmp/mysocket" static int listen_fd; BOOL listen_socket (HWND hwnd) { if ((listen_fd = serv_listen (LISTEN_SOCKET)) < 0) return FALSE; return RegisterListenFD (fd, POLL_IN, hwnd, NULL); } /* * When the server receives the request to connect from a client, * the window hwnd will receive a MSG_FDEVENT message. * Now the server can accept the request. */ int MyWndProc (HWND hwnd, int message, WPARAM wParam, LPARAM lParam) { switch (message) { ... case MSG_FDEVENT: if (LOWORD (wParam) == listen_fd) { /* This message comes from the listen socket fd. */ pid_t pid; uid_t uid; int conn_fd; conn_fd = serv_accept (listen_fd, &pid, &uid); if (conn_fd >= 0) { RegisterListenFD (conn_fd, POLL_IN, hwnd, NULL); } } else { /* Client send a request. */ int fd = LOWORD(wParam); /* Handle the request from client. */ sock_read_t (fd, ...); sock_write_t (fd, ....); } break; ... } } /* * Clients can use the following code to connect itself to the server. */ int conn_fd; if ((conn_fd = cli_conn (LISTEN_SOCKET, 'b')) >= 0) { /* Send a request to the server. */ sock_write_t (fd, ....); /* Get the reply from the server. */ sock_read_t (fd, ....); }
|
|
The blocking version of sock_read_t function.
|
|
|
The blocking version of sock_write_t function.
|
|
||||||||||||
|
Used by clients to connect to a server. This function is used by clients to connect to a server. The created socket will be located at the directory '/var/tmp', and with name of '/var/tmp/xxxxx-c', where 'xxxxx' is the pid of client. and 'c' is a character to distinguish different projects. Note that MiniGUI itself uses 'a' as the project character to create socket between 'mginit' and clients.
|
|
||||||||||||||||
|
Waits for a client connection to arrive, and accept it. This function is used by the server to wait a connection and accept it. After creating a listening socket by calling serv_listen, you can call this function to create a connection with a client. We also obtain the client's PID and UID from the pathname that it must bind before calling us.
|
|
|
Creates a listen socket. This function is used by the server to create a listening socket. Any MiniGUI-Processes application can call this function to create a listening socket. The server, i.e. mginit, of MiniGUI-Processes uses this function to create its listening socket, and named the socket to '/var/tmp/minigui'.
|
|
||||||||||||||||||||
|
Reads data from socket. This function reads data which is count bytes long to the buffer buff from the socket fd.
|
|
||||||||||||||||||||
|
Writes data to socket. This function writes the data block pointed to by buff which is count bytes long to the socket fd.
|
1.4.2