Home | History | Annotate | Download | only in libtest

Lines Matching refs:sockets

32 struct Sockets
34 curl_socket_t *sockets;
35 int count; /* number of sockets actually stored in array */
36 int max_count; /* max number of sockets that fit in allocated array */
41 struct Sockets read, write;
45 * Remove a file descriptor from a sockets array.
47 static void removeFd(struct Sockets* sockets, curl_socket_t fd, int mention)
54 for(i = 0; i < sockets->count; ++i) {
55 if(sockets->sockets[i] == fd) {
56 if(i < sockets->count - 1)
57 memmove(&sockets->sockets[i], &sockets->sockets[i + 1],
58 sizeof(curl_socket_t) * (sockets->count - (i + 1)));
59 --sockets->count;
65 * Add a file descriptor to a sockets array.
67 static void addFd(struct Sockets* sockets, curl_socket_t fd, const char *what)
74 removeFd(sockets, fd, 0);
78 if(!sockets->sockets) {
79 sockets->sockets = malloc(sizeof(curl_socket_t) * 20U);
80 if(!sockets->sockets)
82 sockets->max_count = 20;
84 else if(sockets->count + 1 > sockets->max_count) {
85 curl_socket_t *oldptr = sockets->sockets;
86 sockets->sockets = realloc(oldptr, sizeof(curl_socket_t) *
87 (sockets->max_count + 20));
88 if(!sockets->sockets) {
90 sockets->sockets = oldptr;
93 sockets->max_count += 20;
98 sockets->sockets[sockets->count] = fd;
99 ++sockets->count;
108 struct ReadWriteSockets* sockets = userp;
114 addFd(&sockets->read, s, "read");
117 addFd(&sockets->write, s, "write");
120 removeFd(&sockets->read, s, 1);
121 removeFd(&sockets->write, s, 0);
186 * Update a fd_set with all of the sockets in use.
188 static void updateFdSet(struct Sockets* sockets, fd_set* fdset,
192 for(i = 0; i < sockets->count; ++i) {
193 FD_SET(sockets->sockets[i], fdset);
194 if(*maxFd < sockets->sockets[i] + 1) {
195 *maxFd = sockets->sockets[i] + 1;
214 static void checkFdSet(CURLM *curl, struct Sockets *sockets, fd_set *fdset,
218 for(i = 0; i < sockets->count; ++i) {
219 if(FD_ISSET(sockets->sockets[i], fdset)) {
220 notifyCurl(curl, sockets->sockets[i], evBitmask, name);
233 struct ReadWriteSockets sockets = {{NULL, 0, 0}, {NULL, 0, 0}};
294 multi_setopt(m, CURLMOPT_SOCKETDATA, &sockets);
308 updateFdSet(&sockets.read, &readSet, &maxFd);
309 updateFdSet(&sockets.write, &writeSet, &maxFd);
323 /* Check the sockets for reading / writing */
324 checkFdSet(m, &sockets.read, &readSet, CURL_CSELECT_IN, "read");
325 checkFdSet(m, &sockets.write, &writeSet, CURL_CSELECT_OUT, "write");
353 free(sockets.read.sockets);
354 free(sockets.write.sockets);