Lines Matching defs:sockets

36   curl_socket_t *sockets;
37 int count; /* number of sockets actually stored in array */
38 int max_count; /* max number of sockets that fit in allocated array */
47 * Remove a file descriptor from a sockets array.
49 static void removeFd(struct Sockets *sockets, curl_socket_t fd, int mention)
56 for(i = 0; i < sockets->count; ++i) {
57 if(sockets->sockets[i] == fd) {
58 if(i < sockets->count - 1)
59 memmove(&sockets->sockets[i], &sockets->sockets[i + 1],
60 sizeof(curl_socket_t) * (sockets->count - (i + 1)));
61 --sockets->count;
67 * Add a file descriptor to a sockets array.
69 static void addFd(struct Sockets *sockets, curl_socket_t fd, const char *what)
76 removeFd(sockets, fd, 0);
80 if(!sockets->sockets) {
81 sockets->sockets = malloc(sizeof(curl_socket_t) * 20U);
82 if(!sockets->sockets)
84 sockets->max_count = 20;
86 else if(sockets->count + 1 > sockets->max_count) {
87 curl_socket_t *oldptr = sockets->sockets;
88 sockets->sockets = realloc(oldptr, sizeof(curl_socket_t) *
89 (sockets->max_count + 20));
90 if(!sockets->sockets) {
92 sockets->sockets = oldptr;
95 sockets->max_count += 20;
100 sockets->sockets[sockets->count] = fd;
101 ++sockets->count;
110 struct ReadWriteSockets *sockets = userp;
116 addFd(&sockets->read, s, "read");
119 addFd(&sockets->write, s, "write");
122 removeFd(&sockets->read, s, 1);
123 removeFd(&sockets->write, s, 0);
190 * Update a fd_set with all of the sockets in use.
192 static void updateFdSet(struct Sockets *sockets, fd_set* fdset,
196 for(i = 0; i < sockets->count; ++i) {
197 FD_SET(sockets->sockets[i], fdset);
198 if(*maxFd < sockets->sockets[i] + 1) {
199 *maxFd = sockets->sockets[i] + 1;
218 static void checkFdSet(CURLM *curl, struct Sockets *sockets, fd_set *fdset,
222 for(i = 0; i < sockets->count; ++i) {
223 if(FD_ISSET(sockets->sockets[i], fdset)) {
224 notifyCurl(curl, sockets->sockets[i], evBitmask, name);
237 struct ReadWriteSockets sockets = {{NULL, 0, 0}, {NULL, 0, 0}};
300 multi_setopt(m, CURLMOPT_SOCKETDATA, &sockets);
314 updateFdSet(&sockets.read, &readSet, &maxFd);
315 updateFdSet(&sockets.write, &writeSet, &maxFd);
329 /* Check the sockets for reading / writing */
330 checkFdSet(m, &sockets.read, &readSet, CURL_CSELECT_IN, "read");
331 checkFdSet(m, &sockets.write, &writeSet, CURL_CSELECT_OUT, "write");
359 free(sockets.read.sockets);
360 free(sockets.write.sockets);