diff options
Diffstat (limited to 'src/client.c')
| -rw-r--r-- | src/client.c | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/src/client.c b/src/client.c index 1e15a1e..c6a7ce8 100644 --- a/src/client.c +++ b/src/client.c | |||
| @@ -71,6 +71,14 @@ struct mux_client { | |||
| 71 | static struct collection client_list; | 71 | static struct collection client_list; |
| 72 | pthread_mutex_t client_list_mutex; | 72 | pthread_mutex_t client_list_mutex; |
| 73 | 73 | ||
| 74 | /** | ||
| 75 | * Receive raw data from the client socket. | ||
| 76 | * | ||
| 77 | * @param client Client to read from. | ||
| 78 | * @param buffer Buffer to store incoming data. | ||
| 79 | * @param len Max number of bytes to read. | ||
| 80 | * @return Same as recv() system call. Number of bytes read; when < 0 errno will be set. | ||
| 81 | */ | ||
| 74 | int client_read(struct mux_client *client, void *buffer, uint32_t len) | 82 | int client_read(struct mux_client *client, void *buffer, uint32_t len) |
| 75 | { | 83 | { |
| 76 | usbmuxd_log(LL_SPEW, "client_read fd %d buf %p len %d", client->fd, buffer, len); | 84 | usbmuxd_log(LL_SPEW, "client_read fd %d buf %p len %d", client->fd, buffer, len); |
| @@ -81,6 +89,14 @@ int client_read(struct mux_client *client, void *buffer, uint32_t len) | |||
| 81 | return recv(client->fd, buffer, len, 0); | 89 | return recv(client->fd, buffer, len, 0); |
| 82 | } | 90 | } |
| 83 | 91 | ||
| 92 | /** | ||
| 93 | * Send raw data to the client socket. | ||
| 94 | * | ||
| 95 | * @param client Client to send to. | ||
| 96 | * @param buffer The data to send. | ||
| 97 | * @param len Number of bytes to write. | ||
| 98 | * @return Same as system call send(). Number of bytes written; when < 0 errno will be set. | ||
| 99 | */ | ||
| 84 | int client_write(struct mux_client *client, void *buffer, uint32_t len) | 100 | int client_write(struct mux_client *client, void *buffer, uint32_t len) |
| 85 | { | 101 | { |
| 86 | usbmuxd_log(LL_SPEW, "client_write fd %d buf %p len %d", client->fd, buffer, len); | 102 | usbmuxd_log(LL_SPEW, "client_write fd %d buf %p len %d", client->fd, buffer, len); |
| @@ -91,6 +107,16 @@ int client_write(struct mux_client *client, void *buffer, uint32_t len) | |||
| 91 | return send(client->fd, buffer, len, 0); | 107 | return send(client->fd, buffer, len, 0); |
| 92 | } | 108 | } |
| 93 | 109 | ||
| 110 | /** | ||
| 111 | * Set event mask to use for ppoll()ing the client socket. | ||
| 112 | * Typically POLLOUT and/or POLLIN. Note that this overrides | ||
| 113 | * the current mask, that is, it is not ORing the argument | ||
| 114 | * into the current mask. | ||
| 115 | * | ||
| 116 | * @param client The client to set the event mask on. | ||
| 117 | * @param events The event mask to sert. | ||
| 118 | * @return 0 on success, -1 on error. | ||
| 119 | */ | ||
| 94 | int client_set_events(struct mux_client *client, short events) | 120 | int client_set_events(struct mux_client *client, short events) |
| 95 | { | 121 | { |
| 96 | if((client->state != CLIENT_CONNECTED) && (client->state != CLIENT_CONNECTING2)) { | 122 | if((client->state != CLIENT_CONNECTED) && (client->state != CLIENT_CONNECTING2)) { |
| @@ -103,6 +129,15 @@ int client_set_events(struct mux_client *client, short events) | |||
| 103 | return 0; | 129 | return 0; |
| 104 | } | 130 | } |
| 105 | 131 | ||
| 132 | /** | ||
| 133 | * Wait for an inbound connection on the usbmuxd socket | ||
| 134 | * and create a new mux_client instance for it, and store | ||
| 135 | * the client in the client list. | ||
| 136 | * | ||
| 137 | * @param listenfd the socket fd to accept() on. | ||
| 138 | * @return The connection fd for the client, or < 0 for error | ||
| 139 | * in which case errno will be set. | ||
| 140 | */ | ||
| 106 | int client_accept(int listenfd) | 141 | int client_accept(int listenfd) |
| 107 | { | 142 | { |
| 108 | struct sockaddr_un addr; | 143 | struct sockaddr_un addr; |
