Changeset View
Changeset View
Standalone View
Standalone View
sbin/ggate/ggated/ggated.c
Show First 20 Lines • Show All 520 Lines • ▼ Show 20 Lines | connection_ready(struct ggd_connection *conn) | ||||
return (conn->c_sendfd != -1 && conn->c_recvfd != -1); | return (conn->c_sendfd != -1 && conn->c_recvfd != -1); | ||||
} | } | ||||
static void | static void | ||||
connection_launch(struct ggd_connection *conn) | connection_launch(struct ggd_connection *conn) | ||||
{ | { | ||||
pthread_t td; | pthread_t td; | ||||
int error, pid; | int error, pid; | ||||
int i; | |||||
pid = fork(); | pid = fork(); | ||||
if (pid > 0) | if (pid > 0) | ||||
return; | return; | ||||
else if (pid == -1) { | else if (pid == -1) { | ||||
g_gate_log(LOG_ERR, "Cannot fork: %s.", strerror(errno)); | g_gate_log(LOG_ERR, "Cannot fork: %s.", strerror(errno)); | ||||
return; | return; | ||||
} | } | ||||
Show All 35 Lines | if (error != 0) { | ||||
g_gate_xlog("pthread_create(send_thread): %s.", | g_gate_xlog("pthread_create(send_thread): %s.", | ||||
strerror(error)); | strerror(error)); | ||||
} | } | ||||
error = pthread_create(&td, NULL, recv_thread, conn); | error = pthread_create(&td, NULL, recv_thread, conn); | ||||
if (error != 0) { | if (error != 0) { | ||||
g_gate_xlog("pthread_create(recv_thread): %s.", | g_gate_xlog("pthread_create(recv_thread): %s.", | ||||
strerror(error)); | strerror(error)); | ||||
} | } | ||||
for (i = 0; niothreads && i < niothreads - 1; i++) { | |||||
error = pthread_create(&td, NULL, disk_thread, conn); | |||||
if (error != 0) { | |||||
g_gate_xlog("pthread_create(disk_thread): %s.", | |||||
strerror(error)); | |||||
} | |||||
} | |||||
disk_thread(conn); | disk_thread(conn); | ||||
} | } | ||||
static void | static void | ||||
sendfail(int sfd, int error, const char *fmt, ...) | sendfail(int sfd, int error, const char *fmt, ...) | ||||
{ | { | ||||
struct g_gate_sinit sinit; | struct g_gate_sinit sinit; | ||||
va_list ap; | va_list ap; | ||||
▲ Show 20 Lines • Show All 364 Lines • ▼ Show 20 Lines | main(int argc, char *argv[]) | ||||
int sfd, tmpsfd; | int sfd, tmpsfd; | ||||
unsigned port; | unsigned port; | ||||
bindaddr = htonl(INADDR_ANY); | bindaddr = htonl(INADDR_ANY); | ||||
port = G_GATE_PORT; | port = G_GATE_PORT; | ||||
for (;;) { | for (;;) { | ||||
int ch; | int ch; | ||||
ch = getopt(argc, argv, "a:hnp:R:S:v"); | ch = getopt(argc, argv, "a:hnp:q:R:S:v"); | ||||
if (ch == -1) | if (ch == -1) | ||||
break; | break; | ||||
switch (ch) { | switch (ch) { | ||||
case 'a': | case 'a': | ||||
bindaddr = g_gate_str2ip(optarg); | bindaddr = g_gate_str2ip(optarg); | ||||
if (bindaddr == INADDR_NONE) { | if (bindaddr == INADDR_NONE) { | ||||
errx(EXIT_FAILURE, | errx(EXIT_FAILURE, | ||||
"Invalid IP/host name to bind to."); | "Invalid IP/host name to bind to."); | ||||
} | } | ||||
break; | break; | ||||
case 'n': | case 'n': | ||||
nagle = 0; | nagle = 0; | ||||
break; | break; | ||||
case 'p': | case 'p': | ||||
errno = 0; | errno = 0; | ||||
port = strtoul(optarg, NULL, 10); | port = strtoul(optarg, NULL, 10); | ||||
if (port == 0 && errno != 0) | if (port == 0 && errno != 0) | ||||
errx(EXIT_FAILURE, "Invalid port."); | errx(EXIT_FAILURE, "Invalid port."); | ||||
break; | |||||
case 'q': | |||||
niothreads = strtol(optarg, NULL, 10); | |||||
if (niothreads < 0) | |||||
errx(EXIT_FAILURE, "Invalid queue size."); | |||||
break; | break; | ||||
case 'R': | case 'R': | ||||
errno = 0; | errno = 0; | ||||
rcvbuf = strtoul(optarg, NULL, 10); | rcvbuf = strtoul(optarg, NULL, 10); | ||||
if (rcvbuf == 0 && errno != 0) | if (rcvbuf == 0 && errno != 0) | ||||
errx(EXIT_FAILURE, "Invalid rcvbuf."); | errx(EXIT_FAILURE, "Invalid rcvbuf."); | ||||
break; | break; | ||||
case 'S': | case 'S': | ||||
▲ Show 20 Lines • Show All 64 Lines • Show Last 20 Lines |