|
|
 | | From: | xjaguar | | Subject: | SO_REUSEADDR on Windows | | Date: | Sun, 23 Jan 2005 22:11:02 +0800 |
|
|
 | hi, I come across to the problem of ACE_OS::setsockopt with SO_REUSEADDR, in 5.4.3. Documention says Winsock2's support of SO_REUSEADDR is broken and ignore this option silently. It also says "ACE always sets SO_REUSEADDR = 1", (aec/OS_NS_sys_socket.inl:841). Since ACE_OS::setsockopt is at lowest level of all wrapper, how could ACE set that? I grep the source code roughtly, and don't find any direct call to ::setsockopt. So, how is that done?
-------------------------------------------------------------- There is another problem bothering me, but it is not related to ACE. Please give me some advice, since you guys are solaris experts: SO_REUSEADDR is not working on my solaris box, (solaris 9 sparc). Same code works as expect on linux and windows. Here they are:
#include #include #include #include #include
// print error and clear errno void Perror(const char* msg) { perror(msg); errno = 0; }
int main(int argc, char* argv[]) { int lhdl, chdl; struct sockaddr_in laddr, raddr;
int one = 1, size = sizeof(int);
laddr.sin_family = AF_INET; laddr.sin_port = htons(5150); laddr.sin_addr.s_addr = htonl(INADDR_ANY);
// I want two sockets both at same local port, one is listening and another // connecto to my server.
lhdl = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); if( lhdl == -1) Perror("socket"); chdl = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); if( chdl == -1) Perror("socket"); if( 0 != setsockopt(lhdl, SOL_SOCKET, SO_REUSEADDR, &one, sizeof(int))) Perror("setsockopt"); if( 0 != bind(lhdl, (struct sockaddr*)&laddr, sizeof(laddr))) Perror("bind"); if( 0 != setsockopt(chdl, SOL_SOCKET, SO_REUSEADDR, &one, sizeof(int))) Perror("setsockopt"); if( 0 != bind(chdl, (struct sockaddr*)&laddr, sizeof(laddr))) Perror("bind");
listen(lhdl, 5); Perror("listen");
raddr.sin_family = AF_INET; raddr.sin_port = htons(80); raddr.sin_addr.s_addr = inet_addr("202.38.215.238");
connect(chdl, (struct sockaddr*)&raddr, sizeof(raddr)); Perror("connect");
getchar(); return 0; }
|
|
 | | From: | xjaguar | | Subject: | Re: SO_REUSEADDR on Windows | | Date: | Sun, 23 Jan 2005 22:18:15 +0800 |
|
|
 | sorry for post this _3_ time, my connection is toooooooo pool
"xjaguar" дÈëÓʼþ news:ct0bm4$2d80$1@mail.cn99.com... > hi, > I come across to the problem of ACE_OS::setsockopt with SO_REUSEADDR, in > 5.4.3. Documention says Winsock2's support of SO_REUSEADDR is broken and > ignore > this option silently. It also says "ACE always sets SO_REUSEADDR = 1", > (aec/OS_NS_sys_socket.inl:841). Since ACE_OS::setsockopt is at lowest level > of all wrapper, how could ACE set that? > I grep the source code roughtly, and don't find any direct call to > ::setsockopt. > So, how is that done? > > -------------------------------------------------------------- > There is another problem bothering me, but it is not related to ACE. Please > give me some advice, since you guys are solaris experts: > SO_REUSEADDR is not working on my solaris box, (solaris 9 sparc). Same > code works as expect on linux and windows. Here they are: > > #include > #include > #include > #include > #include > > // print error and clear errno > void Perror(const char* msg) > { > perror(msg); > errno = 0; > } > > int main(int argc, char* argv[]) > { > int lhdl, chdl; > struct sockaddr_in laddr, raddr; > > int one = 1, size = sizeof(int); > > laddr.sin_family = AF_INET; > laddr.sin_port = htons(5150); > laddr.sin_addr.s_addr = htonl(INADDR_ANY); > > // I want two sockets both at same local port, one is listening and > another > // connecto to my server. > > lhdl = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); > if( lhdl == -1) Perror("socket"); > chdl = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); > if( chdl == -1) Perror("socket"); > if( 0 != setsockopt(lhdl, SOL_SOCKET, SO_REUSEADDR, > &one, sizeof(int))) > Perror("setsockopt"); > if( 0 != bind(lhdl, (struct sockaddr*)&laddr, sizeof(laddr))) > Perror("bind"); > if( 0 != setsockopt(chdl, SOL_SOCKET, SO_REUSEADDR, > &one, sizeof(int))) > Perror("setsockopt"); > if( 0 != bind(chdl, (struct sockaddr*)&laddr, sizeof(laddr))) > Perror("bind"); > > listen(lhdl, 5); Perror("listen"); > > raddr.sin_family = AF_INET; > raddr.sin_port = htons(80); > raddr.sin_addr.s_addr = inet_addr("202.38.215.238"); > > connect(chdl, (struct sockaddr*)&raddr, sizeof(raddr)); > Perror("connect"); > > getchar(); > return 0; > } > > > > >
|
|
|