diff options
| author | 2009-05-18 00:39:41 +0200 | |
|---|---|---|
| committer | 2009-05-18 00:39:41 +0200 | |
| commit | ce97f25e9ab038f8a96b6d9c9f1b9d247aeec11c (patch) | |
| tree | 0903d06a654eda8265a142bcb11cd6c0f7ce7503 | |
| parent | a04c396a21d29da832de21c693da18e6cbf56a13 (diff) | |
| download | usbmuxd-ce97f25e9ab038f8a96b6d9c9f1b9d247aeec11c.tar.gz usbmuxd-ce97f25e9ab038f8a96b6d9c9f1b9d247aeec11c.tar.bz2 | |
Added usbmuxd_recv, usbmuxd_recv_timeout, usbmuxd_send, and usbmuxd_disconnect
| -rw-r--r-- | src/libusbmuxd.c | 46 | ||||
| -rw-r--r-- | src/usbmuxd.h | 46 |
2 files changed, 92 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) | |||
| 200 | 200 | ||
| 201 | return -1; | 201 | return -1; |
| 202 | } | 202 | } |
| 203 | |||
| 204 | int usbmuxd_disconnect(int sfd) | ||
| 205 | { | ||
| 206 | return close(sfd); | ||
| 207 | } | ||
| 208 | |||
| 209 | int usbmuxd_send(int sfd, const char *data, uint32_t len, uint32_t *sent_bytes) | ||
| 210 | { | ||
| 211 | int num_sent; | ||
| 212 | |||
| 213 | if (sfd < 0) { | ||
| 214 | return -EINVAL; | ||
| 215 | } | ||
| 216 | |||
| 217 | num_sent = send(sfd, (void*)data, len, 0); | ||
| 218 | if (num_sent < 0) { | ||
| 219 | *sent_bytes = 0; | ||
| 220 | fprintf(stderr, "%s: Error %d when sending: %s\n", __func__, num_sent, strerror(errno)); | ||
| 221 | return num_sent; | ||
| 222 | } else if ((uint32_t)num_sent < len) { | ||
| 223 | fprintf(stderr, "%s: Warning: Did not send enough (only %d of %d)\n", __func__, num_sent, len); | ||
| 224 | } | ||
| 225 | |||
| 226 | *sent_bytes = num_sent; | ||
| 227 | |||
| 228 | return 0; | ||
| 229 | } | ||
| 230 | |||
| 231 | int usbmuxd_recv_timeout(int sfd, char *data, uint32_t len, uint32_t *recv_bytes, unsigned int timeout) | ||
| 232 | { | ||
| 233 | int num_recv = recv_buf_timeout(sfd, (void*)data, len, 0, timeout); | ||
| 234 | if (num_recv < 0) { | ||
| 235 | *recv_bytes = 0; | ||
| 236 | return num_recv; | ||
| 237 | } | ||
| 238 | |||
| 239 | *recv_bytes = num_recv; | ||
| 240 | |||
| 241 | return 0; | ||
| 242 | } | ||
| 243 | |||
| 244 | int usbmuxd_recv(int sfd, char *data, uint32_t len, uint32_t *recv_bytes) | ||
| 245 | { | ||
| 246 | return usbmuxd_recv_timeout(sfd, data, len, recv_bytes, 5000); | ||
| 247 | } | ||
| 248 | |||
diff --git a/src/usbmuxd.h b/src/usbmuxd.h index 15e97ee..ba45ec3 100644 --- a/src/usbmuxd.h +++ b/src/usbmuxd.h | |||
| @@ -42,4 +42,50 @@ int usbmuxd_scan(usbmuxd_scan_result **available_devices); | |||
| 42 | */ | 42 | */ |
| 43 | int usbmuxd_connect(const int handle, const unsigned short tcp_port); | 43 | int usbmuxd_connect(const int handle, const unsigned short tcp_port); |
| 44 | 44 | ||
| 45 | /** | ||
| 46 | * Disconnect. For now, this just closes the socket file descriptor. | ||
| 47 | * | ||
| 48 | * @param sfd socker file descriptor returned by usbmuxd_connect() | ||
| 49 | * | ||
| 50 | * @return 0 on success, -1 on error. | ||
| 51 | */ | ||
| 52 | int usbmuxd_disconnect(int sfd); | ||
| 53 | |||
| 54 | /** | ||
| 55 | * Send data to the specified socket. | ||
| 56 | * | ||
| 57 | * @param sfd socket file descriptor returned by usbmuxd_connect() | ||
| 58 | * @param data buffer to send | ||
| 59 | * @param len size of buffer to send | ||
| 60 | * @param sent_bytes how many bytes sent | ||
| 61 | * | ||
| 62 | * @return 0 on success, a negative errno value otherwise. | ||
| 63 | */ | ||
| 64 | int usbmuxd_send(int sfd, const char *data, uint32_t len, uint32_t *sent_bytes); | ||
| 65 | |||
| 66 | /** | ||
| 67 | * Receive data from the specified socket. | ||
| 68 | * | ||
| 69 | * @param sfd socket file descriptor returned by usbmuxd_connect() | ||
| 70 | * @param data buffer to put the data to | ||
| 71 | * @param len number of bytes to receive | ||
| 72 | * @param recv_bytes number of bytes received | ||
| 73 | * @param timeout how many milliseconds to wait for data | ||
| 74 | * | ||
| 75 | * @return 0 on success, a negative errno value otherwise. | ||
| 76 | */ | ||
| 77 | int usbmuxd_recv_timeout(int sfd, char *data, uint32_t len, uint32_t *recv_bytes, unsigned int timeout); | ||
| 78 | |||
| 79 | /** | ||
| 80 | * Receive data from the specified socket with a default timeout. | ||
| 81 | * | ||
| 82 | * @param sfd socket file descriptor returned by usbmuxd_connect() | ||
| 83 | * @param data buffer to put the data to | ||
| 84 | * @param len number of bytes to receive | ||
| 85 | * @param recv_bytes number of bytes received | ||
| 86 | * | ||
| 87 | * @return 0 on success, a negative errno value otherwise. | ||
| 88 | */ | ||
| 89 | int usbmuxd_recv(int sfd, char *data, uint32_t len, uint32_t *recv_bytes); | ||
| 90 | |||
| 45 | #endif /* __USBMUXD_H */ | 91 | #endif /* __USBMUXD_H */ |
