comparison listener.c @ 63:dcc43965928f

- A nice cleaner structure for tcp (acceptor) forwarding. - still a checkpoint-ish commit - sorted out listening on localhost only
author Matt Johnston <matt@ucc.asn.au>
date Wed, 11 Aug 2004 17:26:47 +0000
parents 20563735e8b5
children e3adf4cf5465
comparison
equal deleted inserted replaced
62:20563735e8b5 63:dcc43965928f
40 listener = ses.listeners[i]; 40 listener = ses.listeners[i];
41 if (listener != NULL) { 41 if (listener != NULL) {
42 for (j = 0; j < listener->nsocks; j++) { 42 for (j = 0; j < listener->nsocks; j++) {
43 sock = listener->socks[j]; 43 sock = listener->socks[j];
44 if (FD_ISSET(sock, readfds)) { 44 if (FD_ISSET(sock, readfds)) {
45 listener->accepter(listener, sock); 45 listener->acceptor(listener, sock);
46 } 46 }
47 } 47 }
48 } 48 }
49 } 49 }
50 } 50 }
51 51
52 52
53 /* accepter(int fd, void* typedata) is a function to accept connections, 53 /* acceptor(int fd, void* typedata) is a function to accept connections,
54 * cleanup(void* typedata) happens when cleaning up */ 54 * cleanup(void* typedata) happens when cleaning up */
55 struct Listener* new_listener(int socks[], unsigned int nsocks, 55 struct Listener* new_listener(int socks[], unsigned int nsocks,
56 int type, void* typedata, 56 int type, void* typedata,
57 void (*accepter)(struct Listener*, int sock), 57 void (*acceptor)(struct Listener* listener, int sock),
58 void (*cleanup)(struct Listener*)) { 58 void (*cleanup)(struct Listener*)) {
59 59
60 unsigned int i, j; 60 unsigned int i, j;
61 struct Listener *newlisten = NULL; 61 struct Listener *newlisten = NULL;
62 /* try get a new structure to hold it */ 62 /* try get a new structure to hold it */
97 newlisten->index = i; 97 newlisten->index = i;
98 newlisten->type = type; 98 newlisten->type = type;
99 newlisten->typedata = typedata; 99 newlisten->typedata = typedata;
100 newlisten->nsocks = nsocks; 100 newlisten->nsocks = nsocks;
101 memcpy(newlisten->socks, socks, nsocks * sizeof(int)); 101 memcpy(newlisten->socks, socks, nsocks * sizeof(int));
102 newlisten->accepter = accepter; 102 newlisten->acceptor = acceptor;
103 newlisten->cleanup = cleanup; 103 newlisten->cleanup = cleanup;
104 104
105 ses.listeners[i] = newlisten; 105 ses.listeners[i] = newlisten;
106 return newlisten; 106 return newlisten;
107 } 107 }