void common_sighandler(int sig)
{
- static time_t lastintr = 0;
- time_t now = time(NULL);
-
switch (sig) {
case SIGINT:
- if (sigint) {
- if (now - lastintr >= 1)
- break;
- } else {
- lastintr = now;
- sigint = true;
- }
+ sigint = true;
return;
case SIGHUP:
return 0;
}
-int tcp_listen_nonblock(const struct sockaddr *addr, socklen_t len)
+int tcp_bind(const struct sockaddr *addr, socklen_t len)
{
int sock;
return -1;
}
- if (setnonblock(sock)) {
+ return sock;
+}
+
+int tcp_listen(const struct sockaddr *addr, socklen_t len)
+{
+ int sock = tcp_bind(addr, len);
+ if (listen(sock, 0) < 0) {
+ UNIXERR("bind");
close(sock);
return -1;
}
+ return sock;
+}
+int tcp_listen_nonblock(const struct sockaddr *addr, socklen_t len)
+{
+ int sock = tcp_bind(addr, len);
+ if (setnonblock(sock)) {
+ close(sock);
+ return -1;
+ }
if (listen(sock, 0) < 0) {
UNIXERR("bind");
close(sock);
return -1;
}
-
return sock;
}
}
}
-extern initcall_t __madinit[], __madexit[];
+extern initcall_t __madinit[];
+extern exitcall_t __madexit[];
static void common_shutdown(void)
{