summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: e2d1b74)
raw | patch | inline | side by side (parent: e2d1b74)
author | Sebastian Harl <sh@tokkee.org> | |
Sat, 26 Oct 2013 12:23:56 +0000 (14:23 +0200) | ||
committer | Sebastian Harl <sh@tokkee.org> | |
Sat, 26 Oct 2013 12:23:56 +0000 (14:23 +0200) |
src/frontend/sock.c | patch | blob | history |
diff --git a/src/frontend/sock.c b/src/frontend/sock.c
index ba9b3a867bb637262f711a2a29618002f7310529..414c90775657294c0408ffb1e8c1eaea78ae8f0d 100644 (file)
--- a/src/frontend/sock.c
+++ b/src/frontend/sock.c
return 0;
} /* connection_accept */
+static int
+socket_handle_incoming(sdb_fe_socket_t *sock,
+ fd_set *ready, fd_set *exceptions)
+{
+ sdb_llist_iter_t *iter;
+ size_t i;
+
+ for (i = 0; i < sock->listeners_num; ++i) {
+ listener_t *listener = sock->listeners + i;
+ if (FD_ISSET(listener->sock_fd, ready))
+ if (connection_accept(sock, listener))
+ continue;
+ }
+
+ iter = sdb_llist_get_iter(sock->open_connections);
+ if (! iter) {
+ sdb_log(SDB_LOG_ERR, "frontend: Failed to acquire iterator "
+ "for open connections");
+ return -1;
+ }
+
+ while (sdb_llist_iter_has_next(iter)) {
+ sdb_object_t *obj = sdb_llist_iter_get_next(iter);
+
+ if (FD_ISSET(CONN(obj)->conn.fd, exceptions))
+ sdb_log(SDB_LOG_INFO, "Exception on fd %d",
+ CONN(obj)->conn.fd);
+
+ if (FD_ISSET(CONN(obj)->conn.fd, ready)) {
+ sdb_llist_iter_remove_current(iter);
+ sdb_channel_write(sock->chan, &obj);
+ }
+ }
+ sdb_llist_iter_destroy(iter);
+ return 0;
+} /* socket_handle_incoming */
+
/*
* public API
*/
connection_handler, /* arg = */ sock);
while (loop->do_loop) {
+ struct timeval timeout = { 1, 0 }; /* one second */
+ sdb_llist_iter_t *iter;
+
+ int max_fd = max_listen_fd;
fd_set ready;
fd_set exceptions;
- int max_fd;
int n;
- struct timeval timeout = { 1, 0 }; /* one second */
- sdb_llist_iter_t *iter;
-
FD_ZERO(&ready);
FD_ZERO(&exceptions);
ready = sockets;
- max_fd = max_listen_fd;
-
iter = sdb_llist_get_iter(sock->open_connections);
if (! iter) {
sdb_log(SDB_LOG_ERR, "frontend: Failed to acquire iterator "
sdb_strerror(errno, buf, sizeof(buf)));
break;
}
-
- if (! n)
+ else if (! n)
continue;
- for (i = 0; i < sock->listeners_num; ++i) {
- listener_t *listener = sock->listeners + i;
- if (FD_ISSET(listener->sock_fd, &ready))
- if (connection_accept(sock, listener))
- continue;
- }
-
- iter = sdb_llist_get_iter(sock->open_connections);
- if (! iter) {
- sdb_log(SDB_LOG_ERR, "frontend: Failed to acquire iterator "
- "for open connections");
+ /* handle new and open connections */
+ if (socket_handle_incoming(sock, &ready, &exceptions))
break;
- }
-
- while (sdb_llist_iter_has_next(iter)) {
- sdb_object_t *obj = sdb_llist_iter_get_next(iter);
-
- if (FD_ISSET(CONN(obj)->conn.fd, &exceptions))
- sdb_log(SDB_LOG_INFO, "Exception on fd %d",
- CONN(obj)->conn.fd);
-
- if (FD_ISSET(CONN(obj)->conn.fd, &ready)) {
- sdb_llist_iter_remove_current(iter);
- sdb_channel_write(sock->chan, &obj);
- }
- }
- sdb_llist_iter_destroy(iter);
}
socket_close(sock);