accept() returns the same socket descriptor
来源:互联网 发布:mysql怎么取消主键 编辑:程序博客网 时间:2024/05/01 14:06
Is there possible that accept() (on redhat Enterprise 4/linux kernel 2.6) return a same socket value for different tcp connections from the same process of a same application and same machine?
I am so surprised that when I got such a result that many connections have the same socket value on server side when I checked the log file!! How is it possible?!!
By the way, I am using TCP blocking socket to listen.
点击(此处)折叠或打开
- main(){
- int fd, clientfd, len, clientlen;
- sockaddr_in address, clientaddress;
- fd = socket(PF_INET, SOCK_STREAM, 0);
- ....
- memset(&address, 0, sizeof address);
- address.sin_address = AF_INET;
- address.sin_port = htons(port);
- ....
- bind(fd, &address, sizeof address);
- listen(fd, 100);
- do {
- clientfd = accept(fd, &clientaddress, &clientlen);
- if (clientfd < 0) {
- ....
- }
- printf("clientfd = %d", clientfd);
- switch(fork()){
- case 0:
- //do something else
- exit(0);
- default:
- ...
- }
- } while(1);
- }
Answers
If server runs in multiple processes (like Apache with mpm worker model), then every process has its own file descriptor numbering starting from 0.
In other words, it is quite possible that different processes will get exact same socket file descriptor number. However, fd number it does not really mean anything. They still refer to different underlying objects, and different local TCP ports.
上一篇:C/S—心跳检测—heartbeat
下一篇:如何判断SOCKET已经断开
- test123
- 编写安全代码——小心有符号数...
- 使用openssl api进行加密解密...
- 一段自己打印自己的c程序...
- sql relay的c++接口
- linux dhcp peizhi roc
- 关于Unix文件的软链接
- 求教这个命令什么意思,我是新...
- sed -e "/grep/d" 是什么意思...
- 谁能够帮我解决LINUX 2.6 10...
- accept() returns the same socket descriptor
- the descriptor is not a socket
- socket Accept()
- socket-accept
- socket-accept
- socket accept
- epoll pthread—share the same epoll file descriptor among threads?
- The Godfather Returns
- The Mummy Returns
- Another MySQL daemon already running with the same unix socket
- Another MySQL daemon already running with the same unix socket.
- Another MySQL daemon already running with the same unix socket
- Another MySQL daemon already running with the same unix socket.
- Another MySQL daemon already running with the same unix socket
- Another MySQL daemon already running with the same unix socket
- Another MySQL daemon already running with the same unix socket
- Another MySQL daemon already running with the same unix socket
- Another MySQL daemon already running with the same unix socket.
- CentOS 7 - The perfect desktop guide
- 阶乘之和
- Linux—Network—Socket—Programming—heartbeat—源代码
- C/S—心跳检测—heartbeat
- 分析Servlet、Filter、Interception和Listener
- accept() returns the same socket descriptor
- 如何判断SOCKET已经断开
- 使用java 和freemarker实现多级菜单(分类)
- Lua环境安装
- (OK) C/S—心跳检测—heartbeat
- java中的缓存技术该如何实现
- 遗产
- batman-adv-kernel-android-(make-depmod-modprobe)
- 抑郁