我正在调试我的应用程序(有点像之前的问题的后续),它本质上是一个玩具点对点客户端。它的工作原理如下:
- 对等点 1 从对等点 2 请求一个块(或多个块)
- 对等点 2 收到请求,并将块发回
并且循环或多或少地重复。这对于较小的文件非常有用,但是对于任何必须分成大量块(比如 250 个 512 字节的块)的文件,它都会死掉。
在 Peer 2(接收请求的那个)上运行 strace 如下所示:
....
[pid 11731] mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f03d0ac9000
[pid 11731] lseek(400, 200704, SEEK_SET) = 200704
[pid 11731] read(400, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"..., 1024) = 1024
[pid 11731] read(400, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"..., 4096) = 4096
[pid 11731] sendto(5, "SF\0\0\1\212\0\0\2\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"..., 522, 0, NULL, 0) = 522
[pid 11731] select(6, [4 5], NULL, NULL, NULL) = 1 (in [5])
[pid 11731] recvfrom(5, "BB\0\0\0\t\0\0\1\213\0\0\2\0test.dat\0\0\0\0\0\0\0\0\0\0"..., 300, 0, NULL, NULL) = 300
[pid 11731] open("test.dat", O_RDONLY) = 401
[pid 11731] fstat(401, {st_dev=makedev(8, 4), st_ino=9187328, st_mode=S_IFREG|0644, st_nlink=1, st_uid=1000, st_gid=1000, st_blksize=4096, st_blocks=20480, st_size=10485760, st_atime=2012/10/03-10:25:29, st_mtime=2012/10/03-10:25:34, st_ctime=2012/10/03-10:25:34}) = 0
[pid 11731] mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f03d0ac8000
[pid 11731] lseek(401, 200704, SEEK_SET) = 200704
[pid 11731] read(401, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"..., 1536) = 1536
[pid 11731] read(401, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"..., 4096) = 4096
[pid 11731] sendto(5, "SF\0\0\1\213\0\0\2\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"..., 522, 0, NULL,
Peer 1(发送请求的那个)上的 strace 结果如下所示:
....
[pid 11741] sendto(5, "BB\0\0\0\t\0\0\5\213\0\0\2\0test.dat\0\0\0\0\0\0\0\0\0\0"..., 300, 0, NULL, 0) = 300
[pid 11741] sendto(5, "BB\0\0\0\t\0\0\5\214\0\0\2\0test.dat\0\0\0\0\0\0\0\0\0\0"..., 300, 0, NULL, 0) = 300
[pid 11741] sendto(5, "BB\0\0\0\t\0\0\5\215\0\0\2\0test.dat\0\0\0\0\0\0\0\0\0\0"..., 300, 0, NULL, 0) = 300
[pid 11741] sendto(5, "BB\0\0\0\t\0\0\5\216\0\0\2\0test.dat\0\0\0\0\0\0\0\0\0\0"..., 300, 0, NULL, 0) = 300
[pid 11741] sendto(5, "BB\0\0\0\t\0\0\5\217\0\0\2\0test.dat\0\0\0\0\0\0\0\0\0\0"..., 300, 0, NULL, 0) = 300
[pid 11741] sendto(5, "BB\0\0\0\t\0\0\5\220\0\0\2\0test.dat\0\0\0\0\0\0\0\0\0\0"..., 300, 0, NULL, 0) = 300
[pid 11741] sendto(5, "BB\0\0\0\t\0\0\5\221\0\0\2\0test.dat\0\0\0\0\0\0\0\0\0\0"..., 300, 0, NULL, 0
发送时都死了。我不完全确定为什么。如果有人能对此有所了解,我将不胜感激!