... | ... |
@@ -3,12 +3,6 @@ |
3 | 3 |
* |
4 | 4 |
* Handy functions for IPv4 socket connections. |
5 | 5 |
* |
6 |
- * History: |
|
7 |
- * 28/01/2014 Creation |
|
8 |
- * 27/05/2014 New API. |
|
9 |
- * 28/05/2014 Implement the ipv4_* functions. |
|
10 |
- * 10/06/2014 Implement the sselect functions using select as backend. |
|
11 |
- * |
|
12 | 6 |
* Author: Dario Rodriguez dario@softhome.net |
13 | 7 |
* This file is licensed under the terms of the GNU LGPL v2+ |
14 | 8 |
*/ |
... | ... |
@@ -333,8 +327,10 @@ sselect_getread(sselect *paramssel, int *fds, int sizefds) |
333 | 327 |
if(ssel==NULL || fds==NULL || sizefds<1) |
334 | 328 |
return(-1); |
335 | 329 |
for(n=0,i=ssel->readresultreturned;i<ssel->maxfd && n<sizefds;i++) { |
336 |
- if(FD_ISSET(i,&(ssel->readresult))) |
|
330 |
+ if(FD_ISSET(i,&(ssel->readresult))) { |
|
337 | 331 |
fds[n++]=i; |
332 |
+ FD_CLR(i,&(ssel->readresult)); |
|
333 |
+ } |
|
338 | 334 |
} |
339 | 335 |
ssel->readresultreturned=i; |
340 | 336 |
return(n); |
... | ... |
@@ -348,13 +344,49 @@ sselect_getwrite(sselect *paramssel, int *fds, int sizefds) |
348 | 344 |
if(ssel==NULL || fds==NULL || sizefds<1) |
349 | 345 |
return(-1); |
350 | 346 |
for(n=0,i=ssel->writeresultreturned;i<ssel->maxfd && n<sizefds;i++) { |
351 |
- if(FD_ISSET(i,&(ssel->writeresult))) |
|
347 |
+ if(FD_ISSET(i,&(ssel->writeresult))) { |
|
352 | 348 |
fds[n++]=i; |
349 |
+ FD_CLR(i,&(ssel->writeresult)); |
|
350 |
+ } |
|
353 | 351 |
} |
354 | 352 |
ssel->writeresultreturned=i; |
355 | 353 |
return(n); |
356 | 354 |
} |
357 | 355 |
|
356 |
+/* advanced sselect functions */ |
|
357 |
+int |
|
358 |
+sselect_getreadfiltered(sselect *paramssel, fd_set *filter, int *fds, int sizefds) |
|
359 |
+{ |
|
360 |
+ int i,n; |
|
361 |
+ _sselect *ssel=(_sselect *)paramssel; |
|
362 |
+ if(ssel==NULL || fds==NULL || sizefds<1) |
|
363 |
+ return(-1); |
|
364 |
+ for(n=0,i=0;i<ssel->maxfd && n<sizefds;i++) { |
|
365 |
+ if(FD_ISSET(i,&(ssel->readresult)) && FD_ISSET(i,filter)) { |
|
366 |
+ fds[n++]=i; |
|
367 |
+ FD_CLR(i,&(ssel->readresult)); |
|
368 |
+ } |
|
369 |
+ } |
|
370 |
+ return(n); |
|
371 |
+} |
|
372 |
+ |
|
373 |
+int |
|
374 |
+sselect_getwritefiltered(sselect *paramssel, fd_set *filter, int *fds, int sizefds) |
|
375 |
+{ |
|
376 |
+ int i,n; |
|
377 |
+ _sselect *ssel=(_sselect *)paramssel; |
|
378 |
+ if(ssel==NULL || fds==NULL || sizefds<1) |
|
379 |
+ return(-1); |
|
380 |
+ for(n=0,i=0;i<ssel->maxfd && n<sizefds;i++) { |
|
381 |
+ if(FD_ISSET(i,&(ssel->writeresult)) && FD_ISSET(i,filter)) { |
|
382 |
+ fds[n++]=i; |
|
383 |
+ FD_CLR(i,&(ssel->writeresult)); |
|
384 |
+ } |
|
385 |
+ } |
|
386 |
+ return(n); |
|
387 |
+} |
|
388 |
+ |
|
389 |
+ |
|
358 | 390 |
/* aux functions */ |
359 | 391 |
void |
360 | 392 |
sock_setfast(int fd) |
... | ... |
@@ -8,12 +8,6 @@ |
8 | 8 |
* is to integrate the sock_connect() timeout inside the main |
9 | 9 |
* loop as to don't be blocking. |
10 | 10 |
* |
11 |
- * History: |
|
12 |
- * 27/01/2014 Creation |
|
13 |
- * 3/04/2014 Add async-connect functions, add fd_set to select |
|
14 |
- * 27/05/2014 Rethought the API; separate ipv4 from general functions, |
|
15 |
- * rework select so that epoll usage is possible. |
|
16 |
- * |
|
17 | 11 |
* Documentation used: |
18 | 12 |
* http://www.beej.us/guide/bgnet/output/html/multipage/getaddrinfoman.html |
19 | 13 |
* |
... | ... |
@@ -48,6 +42,11 @@ int sselect_wait(sselect *ssel, int ms); |
48 | 42 |
int sselect_getread(sselect *ssel, int *fds, int sizefds); |
49 | 43 |
int sselect_getwrite(sselect *ssel, int *fds, int sizefds); |
50 | 44 |
|
45 |
+/* advanced sselect functions */ |
|
46 |
+int sselect_getreadfiltered(sselect *ssel, fd_set *filter, int *fds, int sizefds); |
|
47 |
+int sselect_getwritefiltered(sselect *ssel, fd_set *filter, int *fds, int sizefds); |
|
48 |
+ |
|
49 |
+/* socket configuration functions */ |
|
51 | 50 |
void sock_setfast(int fd); /* mark as low-bandwidth interactive stream */ |
52 | 51 |
void sock_setunsafe(int fd); /* for server sockets, configure reuseaddress, linger: only suitable for intranet usage */ |
53 | 52 |
|