- 论坛徽章:
- 0
|
本帖最后由 chobit_s 于 2011-08-24 23:51 编辑
- #include <stdio.h>
- #include <unistd.h>
- #include <signal.h>
- #include <sys/socket.h>
- #include <netinet/in.h>
- static int sockfd;
- void sigint(int num)
- {
- close(sockfd);
- printf("closed\n");
- }
- int main(int argc, char **argv)
- {
- char buf[512];
- int len;
- signal(SIGINT, sigint);
- sockfd = socket(AF_INET, SOCK_RAW, IPPROTO_ICMP);
- len = recv(sockfd, (void *)buf, 512, 0);
- if (len < 0) {
- perror("recv");
- return -1;
- }
- return 0;
- }
复制代码 测试结果:
# ./a.out
[ctrl+c]
^Cclosed
recv: Bad file descriptor
我追2.6.11的代码:
recv:
sys_recv-->..->sk_common_recv->raw_recvmsg->skb_recv_datagram->wait_packet:
prepare_to_wait_exclusive(sk->sleep, ...)
.....
schedule_timeout();
finish_wait(sk->sk_sleep, &wait); //finish_wait 内会对sk_sleep引用,但是close会设置成NULL
close:
sys_close-> ..-> sk_common_release-> sock_orphan:
...
sk->sk_sleep = NULL;
...
这两处会不会出现矛盾呢? |
|