-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtool.c
More file actions
44 lines (40 loc) · 923 Bytes
/
tool.c
File metadata and controls
44 lines (40 loc) · 923 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
38
39
40
41
42
43
44
#include "tool.h"
void aeGetTime(long *seconds, long *milliseconds)
{
struct timeval tv;
gettimeofday(&tv, NULL);
*seconds = tv.tv_sec;
*milliseconds = tv.tv_usec/1000;
}
int setnoblocking (int fd){
int old_option = fcntl(fd,F_GETFL );
int new_optin = old_option | O_NONBLOCK;
fcntl(fd,F_SETFL,new_optin);
return old_option;
}
void addfd(int epollfd, int fd){
struct epoll_event event;
event.data.fd = fd;
event.events = EPOLLIN | EPOLLET;
epoll_ctl(epollfd,EPOLL_CTL_ADD,fd,&event);
setnoblocking(fd);
}
/*
*void sig_handler(int sig){
* int save_errno = errno;
* int msg = sig;
* send(pipefd[1],(char *)&msg,1,0);
* errno = save_errno;
*}
*
*/
/*
*void addsig(int sig){
* struct sigaction sa;
* memset( &sa,0,sizeof(sa));
* sa.sa_handler = sig_handler;
* sa.sa_flags |= SA_RESTART;
* sigfillset( &sa.sa_mask);
* assert(sigaction(sig,&sa,NULL) != -1);
*}
*/