14.1 在图 14-1 中,如果当我们重新设置 SIGALRM 的信号处理函数时进程未曾建立过 SIGALRM 的任何信号处理函数,那将会发生什么?
SIGALRM 默认动作是终止进程,因此进程被终止
14.2 在图 14-1 中,如果进程已设置了一个 alarm 定时器,content_timeo 就显示一个警告。修改该函数,使得它在 connect 调用之后和自身返回之前重新设置这个 alarm 定时器。
➜ progs git :(master ) ✗ ./a .out $ {ip } 30000 3
alarm already set ! ori = 10
conn_left = 1 conn_use = 2 new_set = 8
connect succ !
original set
^C
14.3 如下修改图 11-11: 在调用 read 之前指定 MSG_PEEK 标志调用 recv,recv 返回后再以 FIONREAD 命令调用 ioctl,并显示已排队在套接字接收缓冲区中的字节数,然后调用 read 真正读入数据。
➜ progs git :(master ) ✗ ./a .out hansonyang .com hansondaytime
connect to [47.107 .123.118 :50000 ] succ !
there are [ 24 ] bytes in recv buffer -- by MSG_PEEK
there are [ 24 ] bytes in recv buffer -- by ioctl
read 24 bytes from recv buffer content = Sat Feb 9 14 :25 :01 2019
there are [ 0 ] bytes in recv buffer -- by MSG_PEEK
there are [ 0 ] bytes in recv buffer -- by ioctl
server cut connection -- peek
14.4 如果进程自然掉出 main 函数末尾,而不是调用 exit 退出,标准 IO 缓冲区中尚未输出的数据将会发生什么?
main 函数退出后,C 启动例程会调用 exit(main(argc, argv)) 仍然会刷清缓冲区中未输出的内容。
14.5 按照图 14-14 之后讲解的两个方法修改图中程序,验证它们确实能够解决缓冲问题。