summaryrefslogtreecommitdiffstats
path: root/src/libusbmuxd.c
diff options
context:
space:
mode:
authorGravatar Nikias Bassen2009-05-18 00:39:41 +0200
committerGravatar Nikias Bassen2009-05-18 00:39:41 +0200
commitce97f25e9ab038f8a96b6d9c9f1b9d247aeec11c (patch)
tree0903d06a654eda8265a142bcb11cd6c0f7ce7503 /src/libusbmuxd.c
parenta04c396a21d29da832de21c693da18e6cbf56a13 (diff)
downloadusbmuxd-ce97f25e9ab038f8a96b6d9c9f1b9d247aeec11c.tar.gz
usbmuxd-ce97f25e9ab038f8a96b6d9c9f1b9d247aeec11c.tar.bz2
Added usbmuxd_recv, usbmuxd_recv_timeout, usbmuxd_send, and usbmuxd_disconnect
Diffstat (limited to 'src/libusbmuxd.c')
-rw-r--r--src/libusbmuxd.c46
1 files changed, 46 insertions, 0 deletions
diff --git a/src/libusbmuxd.c b/src/libusbmuxd.c
index c8acbf8..4cd0a6d 100644
--- a/src/libusbmuxd.c
+++ b/src/libusbmuxd.c
@@ -200,3 +200,49 @@ int usbmuxd_connect(const int handle, const unsigned short tcp_port)
return -1;
}
+
+int usbmuxd_disconnect(int sfd)
+{
+ return close(sfd);
+}
+
+int usbmuxd_send(int sfd, const char *data, uint32_t len, uint32_t *sent_bytes)
+{
+ int num_sent;
+
+ if (sfd < 0) {
+ return -EINVAL;
+ }
+
+ num_sent = send(sfd, (void*)data, len, 0);
+ if (num_sent < 0) {
+ *sent_bytes = 0;
+ fprintf(stderr, "%s: Error %d when sending: %s\n", __func__, num_sent, strerror(errno));
+ return num_sent;
+ } else if ((uint32_t)num_sent < len) {
+ fprintf(stderr, "%s: Warning: Did not send enough (only %d of %d)\n", __func__, num_sent, len);
+ }
+
+ *sent_bytes = num_sent;
+
+ return 0;
+}
+
+int usbmuxd_recv_timeout(int sfd, char *data, uint32_t len, uint32_t *recv_bytes, unsigned int timeout)
+{
+ int num_recv = recv_buf_timeout(sfd, (void*)data, len, 0, timeout);
+ if (num_recv < 0) {
+ *recv_bytes = 0;
+ return num_recv;
+ }
+
+ *recv_bytes = num_recv;
+
+ return 0;
+}
+
+int usbmuxd_recv(int sfd, char *data, uint32_t len, uint32_t *recv_bytes)
+{
+ return usbmuxd_recv_timeout(sfd, data, len, recv_bytes, 5000);
+}
+