summaryrefslogtreecommitdiffhomepage
path: root/listener.c
diff options
context:
space:
mode:
authorMatt Johnston <matt@ucc.asn.au>2004-08-10 17:09:52 +0000
committerMatt Johnston <matt@ucc.asn.au>2004-08-10 17:09:52 +0000
commita712baa8e566bfd8403a3e2bfdf350a0dc50ea9f (patch)
tree87dd64b7ca8331c29936a32aab69e9f09f63dccf /listener.c
parent254e8e34524db48e5ad73d26a923d20b03dd8bf3 (diff)
just checkpointing
--HG-- extra : convert_revision : fbbf404290f3fea3dfa9f6f53eba9389057e9044
Diffstat (limited to 'listener.c')
-rw-r--r--listener.c42
1 files changed, 28 insertions, 14 deletions
diff --git a/listener.c b/listener.c
index 7296a61..3022bd5 100644
--- a/listener.c
+++ b/listener.c
@@ -14,15 +14,16 @@ void listeners_initialise() {
void set_listener_fds(fd_set * readfds) {
- unsigned int i;
+ unsigned int i, j;
struct Listener *listener;
/* check each in turn */
for (i = 0; i < ses.listensize; i++) {
listener = ses.listeners[i];
if (listener != NULL) {
- TRACE(("set listener fd %d", listener->sock));
- FD_SET(listener->sock, readfds);
+ for (j = 0; j < listener->nsocks; j++) {
+ FD_SET(listener->socks[j], readfds);
+ }
}
}
}
@@ -30,16 +31,19 @@ void set_listener_fds(fd_set * readfds) {
void handle_listeners(fd_set * readfds) {
- unsigned int i;
+ unsigned int i, j;
struct Listener *listener;
+ int sock;
/* check each in turn */
for (i = 0; i < ses.listensize; i++) {
listener = ses.listeners[i];
if (listener != NULL) {
- TRACE(("handle listener num %d fd %d", i, listener->sock));
- if (FD_ISSET(listener->sock, readfds)) {
- listener->accepter(listener);
+ for (j = 0; j < listener->nsocks; j++) {
+ sock = listener->socks[j];
+ if (FD_ISSET(sock, readfds)) {
+ listener->accepter(listener, sock);
+ }
}
}
}
@@ -48,8 +52,9 @@ void handle_listeners(fd_set * readfds) {
/* accepter(int fd, void* typedata) is a function to accept connections,
* cleanup(void* typedata) happens when cleaning up */
-struct Listener* new_listener(int sock, int type, void* typedata,
- void (*accepter)(struct Listener*),
+struct Listener* new_listener(int socks[], unsigned int nsocks,
+ int type, void* typedata,
+ void (*accepter)(struct Listener*, int sock),
void (*cleanup)(struct Listener*)) {
unsigned int i, j;
@@ -65,7 +70,9 @@ struct Listener* new_listener(int sock, int type, void* typedata,
if (i == ses.listensize) {
if (ses.listensize > MAX_LISTENERS) {
TRACE(("leave newlistener: too many already"));
- close(sock);
+ for (j = 0; j < nsocks; j++) {
+ close(socks[i]);
+ }
return NULL;
}
@@ -80,15 +87,18 @@ struct Listener* new_listener(int sock, int type, void* typedata,
}
}
- ses.maxfd = MAX(ses.maxfd, sock);
+ for (j = 0; j < nsocks; j++) {
+ ses.maxfd = MAX(ses.maxfd, socks[j]);
+ }
- TRACE(("new listener num %d fd %d", i, sock));
+ TRACE(("new listener num %d ", i));
newlisten = (struct Listener*)m_malloc(sizeof(struct Listener));
newlisten->index = i;
newlisten->type = type;
newlisten->typedata = typedata;
- newlisten->sock = sock;
+ newlisten->nsocks = nsocks;
+ memcpy(newlisten->socks, socks, nsocks * sizeof(int));
newlisten->accepter = accepter;
newlisten->cleanup = cleanup;
@@ -116,11 +126,15 @@ struct Listener * get_listener(int type, void* typedata,
void remove_listener(struct Listener* listener) {
+ unsigned int j;
+
if (listener->cleanup) {
listener->cleanup(listener);
}
- close(listener->sock);
+ for (j = 0; j < listener->nsocks; j++) {
+ close(listener->socks[j]);
+ }
ses.listeners[listener->index] = NULL;
m_free(listener);