-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutil.cpp
More file actions
37 lines (36 loc) · 724 Bytes
/
util.cpp
File metadata and controls
37 lines (36 loc) · 724 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include "util.h"
static void signalHandler(int nSigno)
{
signal(nSigno, signalHandler);
switch (nSigno)
{
case SIGPIPE:
printf("Process will not exit\n");
break;
default:
printf("%d signal unregister\n", nSigno);
break;
}
}
void ignSigpipe()
{
signal(SIGPIPE, &signalHandler);
}
int setNonblocking(int fd)
{
//获取套接字选项值
int flag = fcntl(fd, F_GETFL, 0);
if (flag == -1)
{
perror("use fcntl getfl is fail.\n");
return -1;
}
//设置套接字选项值
flag |= O_NONBLOCK;
if (fcntl(fd, F_SETFL, flag) == -1)
{
perror("use fcntl setfl is fail.\n");
return -1;
}
return 0;
}