summaryrefslogtreecommitdiffstats
path: root/src/client.c
diff options
context:
space:
mode:
authorGravatar Mikkel Kamstrup Erlandsen2014-03-19 13:28:25 +0100
committerGravatar Martin Szulecki2014-03-24 17:01:30 +0100
commitc4e9a48bfd362290822cc845b077801801d0197a (patch)
tree03d660ef97bba71b586d3bcd03c4d7460b437798 /src/client.c
parent16428372666a32f7493b7b4f949d6ed5c37118ef (diff)
downloadusbmuxd-c4e9a48bfd362290822cc845b077801801d0197a.tar.gz
usbmuxd-c4e9a48bfd362290822cc845b077801801d0197a.tar.bz2
client: add a bunch of comments and function docs
Diffstat (limited to 'src/client.c')
-rw-r--r--src/client.c35
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 {
static struct collection client_list;
pthread_mutex_t client_list_mutex;
+/**
+ * Receive raw data from the client socket.
+ *
+ * @param client Client to read from.
+ * @param buffer Buffer to store incoming data.
+ * @param len Max number of bytes to read.
+ * @return Same as recv() system call. Number of bytes read; when < 0 errno will be set.
+ */
int client_read(struct mux_client *client, void *buffer, uint32_t len)
{
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)
return recv(client->fd, buffer, len, 0);
}
+/**
+ * Send raw data to the client socket.
+ *
+ * @param client Client to send to.
+ * @param buffer The data to send.
+ * @param len Number of bytes to write.
+ * @return Same as system call send(). Number of bytes written; when < 0 errno will be set.
+ */
int client_write(struct mux_client *client, void *buffer, uint32_t len)
{
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)
return send(client->fd, buffer, len, 0);
}
+/**
+ * Set event mask to use for ppoll()ing the client socket.
+ * Typically POLLOUT and/or POLLIN. Note that this overrides
+ * the current mask, that is, it is not ORing the argument
+ * into the current mask.
+ *
+ * @param client The client to set the event mask on.
+ * @param events The event mask to sert.
+ * @return 0 on success, -1 on error.
+ */
int client_set_events(struct mux_client *client, short events)
{
if((client->state != CLIENT_CONNECTED) && (client->state != CLIENT_CONNECTING2)) {
@@ -103,6 +129,15 @@ int client_set_events(struct mux_client *client, short events)
return 0;
}
+/**
+ * Wait for an inbound connection on the usbmuxd socket
+ * and create a new mux_client instance for it, and store
+ * the client in the client list.
+ *
+ * @param listenfd the socket fd to accept() on.
+ * @return The connection fd for the client, or < 0 for error
+ * in which case errno will be set.
+ */
int client_accept(int listenfd)
{
struct sockaddr_un addr;