diff options
author | Eric Wong <normalperson@yhbt.net> | 2013-04-14 00:50:09 +0000 |
---|---|---|
committer | Eric Wong <normalperson@yhbt.net> | 2013-04-17 03:35:14 +0000 |
commit | 7b097d6129a7971197430d817682163adb8e2e8a (patch) | |
tree | b2bd80fc3663be72c22732938190607ce090c481 /accept_loop.c | |
parent | 449b85daa42cae1b9542a26e6dd52a1db38cce93 (diff) | |
download | cmogstored-7b097d6129a7971197430d817682163adb8e2e8a.tar.gz |
getpeername() does not work on unconnected sockets. For error-handling, unconnected sockets is a fairly common occurrence, so we want to get the address early on when we know the address is still valid. For IPv4 addresses, this does not increase memory overhead at all. IPv6 addresses[1] does require an additional heap allocation, but it does not need to be aligned since it is infrequently accessed. If IPv6 becomes common, we may need to expand our per-client storage to 192 bytes (from 128) on 64-bit (or see if we may pack data more carefully). [1] IPv6 addresses are rare with MogileFS, as MogileFS does not currently support them.
Diffstat (limited to 'accept_loop.c')
-rw-r--r-- | accept_loop.c | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/accept_loop.c b/accept_loop.c index d5eb840..7d62e17 100644 --- a/accept_loop.c +++ b/accept_loop.c @@ -90,16 +90,21 @@ void *mog_accept_loop(void *arg) { struct mog_accept *ac = arg; int accept_fd = mog_fd_of(ac)->fd; + union mog_sockaddr msa; pthread_cleanup_push(accept_loop_cleanup, NULL); for (;;) { + struct sockaddr *sa = mog_sockaddr_sa(&msa); + socklen_t salen = (socklen_t)sizeof(msa); + int client_fd; + /* pthread cancellation point */ - int client_fd = mog_accept_fn(accept_fd, NULL, NULL); + client_fd = mog_accept_fn(accept_fd, sa, &salen); if (client_fd >= 0) { mog_cancel_disable(); - ac->post_accept_fn(client_fd, ac->svc); + ac->post_accept_fn(client_fd, ac->svc, sa, salen); mog_cancel_enable(); } else { accept_error_check(ac); |