MiniGUI API Reference (MiniGUI-Processes)
v5.0.6
A mature and proven cross-platform GUI system for embedded and smart IoT devices
|
MiniGUI-Processes uses UNIX domain socket to build the communication between the server and the clients. More...
Macros | |
#define | sock_write(fd, buff, count) sock_write_t(fd, buff, count, 0) |
The blocking version of sock_write_t function. More... | |
#define | sock_read(fd, buff, count) sock_read_t(fd, buff, count, 0) |
The blocking version of sock_read_t function. More... | |
Functions | |
MG_EXPORT int | serv_listen (const char *name) |
Creates a listen socket. More... | |
MG_EXPORT int | serv_accept (int listenfd, pid_t *pidptr, uid_t *uidptr) |
Waits for a client connection to arrive, and accept it. More... | |
MG_EXPORT int | cli_conn (const char *name, char project) |
Used by clients to connect to a server. More... | |
MG_EXPORT ssize_t | sock_read_t (int fd, void *buff, size_t count, DWORD timeout) |
Reads data from socket. More... | |
MiniGUI-Processes uses UNIX domain socket to build the communication between the server and the clients.
You can also use the underlay interfaces which MiniGUI uses to create your own UNIX domain socket.
Example:
#define sock_read | ( | fd, | |
buff, | |||
count | |||
) | sock_read_t(fd, buff, count, 0) |
The blocking version of sock_read_t function.
#define sock_write | ( | fd, | |
buff, | |||
count | |||
) | sock_write_t(fd, buff, count, 0) |
int cli_conn | ( | const char * | name, |
char | project | ||
) |
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.
name | The name of the well-known listen socket (created by server). |
project | A character to distinguish different projects (Do NOT use 'a'). |
int serv_accept | ( | int | listenfd, |
pid_t * | pidptr, | ||
uid_t * | uidptr | ||
) |
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.
listenfd | The fd of listen socket. |
pidptr | The client PID will be saved to this buffer when this function returns. |
uidptr | The client UID will be saved to this buffer when this function returns. |
int serv_listen | ( | const char * | name | ) |
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'.
name | The path name of the listening socket. |
ssize_t sock_read_t | ( | int | fd, |
void * | buff, | ||
size_t | count, | ||
DWORD | timeout | ||
) |
Reads data from socket.
This function reads data which is count bytes long to the buffer buff from the socket fd.
fd | The file descriptor of the socket. |
buff | The buffer used to save the data. |
count | The length in bytes of the buffer. |
timeout | An upper bound on the amount of time elapsed before sock_read_t returns. When it is zero, sock_read_t can block indefinitely. The timeout value is in the tick count of MiniGUI, and tick count of MiniGUI is in unit of 10 milliseconds. |
SOCKERR_OK | Read data successfully. |
SOCKERR_IO | There are some I/O errors occurred. |
SOCKERR_CLOSED | The socket has been closed by the peer. |
SOCKERR_INVARG | You passed invalid arguments. |
SOCKERR_TIMEOUT | Timeout. |