Tuesday 15 September 2015

c - epoll_wait blocking on signalled socket -


I will post a code to excuse my long post so that I can understand how the problem is facing, If a indicated socket is added to the example example, epoll_wait will not block on the example example. The following example has given me this value:

  #include  # Include & lt; Arpa / inet.h & gt; # Include & lt; Stdio.h & gt; # Include & lt; Stdlib.h & gt; # Include & lt; Unistd.h & gt; # Include & lt; Errno.h & gt; #include & lt; String.h & gt; # Include & lt; Sys / types.h & gt; # Include & lt; Time.h> # Include & lt; Sys / epoll.h & gt; Int MAX_EVENT_COUNT = 10; Int main (int argc, char * argv []) {int epollfd = epoll_create (MAX_EVENT_COUNT); If (epollfd == -1) {printf ("\ nError: Apol_cat \ n"); Return 1; } Epoll_event ev; Memset (& amp; EV, 0, sizeof (EV)); Ev.events = EPOLLIN | EPOLLET; Int Pipiphade [2]; If (pipes) == -1) {mirror ("pipe"); Exhaust (EXIT_FAILURE); } Four f = 'a'; Write (piped [1], & amp; ch, 1); If (Apol_ttl (ApollFED, EPOLLCTL_ADD, Pipfed [0], and AV) == -1) {printf ("\ nError: Apoll ad result \ n"); Return 1; } Epoll_event rawResult [MAX_EVENT_COUNT]; Int32_t res = epoll_wait (Apollof, raw result, MAX_EVENT_COUNT, -1); If (res! = 1) {printf ("\ n Apol problem \ n"); } Other {printf ("\ nfine \ n"); }}   

Although the following example is very similar, but this time I add a silicated socket to the impolove, this time the epoll_wait call block

  # Include & lt; Sys / socket.h & gt; #include & lt; Netinet / in.h> # Include & lt; Arpa / inet.h & gt; # Include & lt; Stdio.h & gt; # Include & lt; Stdlib.h & gt; # Include & lt; Unistd.h & gt; # Include & lt; Errno.h & gt; #include & lt; String.h & gt; # Include & lt; Sys / types.h & gt; # Include & lt; Time.h> # Include & lt; Sys / epoll.h & gt; Int MAX_EVENT_COUNT = 10; Int main (int argc, char * argv []) {int listenfd = 0; {Struct sockaddr_in serv_addr; Four transmitted buff [1025]; Listenfd = socket (AF_INET, SOCK_STREAM, 0); Memos (& amp; serv_addr, '0', ss (serv_addr)); Memeset (posted buff, '0', size (sender buff)); Serv_addr.sin_family = AF_INET; Serv_addr.sin_addr.s_addr = htonl (INADDR_ANY); Serv_addr.sin_port = htons (5000); Tie (Schroeder, (Structured Socadar *) and all-ADRR, shaped (all-ADE); Listen (listenfd, 10); } Int sockfd = 0, n = 0; Four Rick Burf [1024]; Struct sockaddr_in serv_addr; Mammateset (Ricochet, '0', Psychophobic); If ((sockfd = socket (AF_INET, SOCK_STREAM, 0)) lt; 0) {printf ("\ nError: could not create socket \ n"); Return 1; } Memeset (& serv_addr, '0', ss (serv_addr)); Serv_addr.sin_family = AF_INET; Serv_addr.sin_port = htons (5000); If (inet_pton (AF_INET, "127.0.0.1", & amp; serv_addr.sin_addr) & lt; = 0} {printf ("\ n inet_pton error occurred \ n"); Return 1; } If (connect (sockfd, (struct sockaddr *) and serv_addr, sizeof (serv_addr)) 0} {printf ("\ nerror: connect failed \ n"); Return 1; } Int connfd = accept (listenfd, (struct sockaddr *) NULL, NULL); Int Applied = Apol_Creat (MAX_EVENT_COUNT); If (epollfd == -1) {printf ("\ nError: Apol_cat \ n"); Return 1; } Epoll_event ev; Memset (& amp; EV, 0, sizeof (EV)); Ev.events = EPOLLIN | EPOLLET; If (epoll_ctl (epoll_ct, EPOLL_CTL_ADD, sockfd, & amp; ev) == -1) {printf ("\ nError: Apol ad result \ n"); Return 1; } Epoll_event rawResult [MAX_EVENT_COUNT]; Int32_t res = epoll_wait (Apollof, raw result, MAX_EVENT_COUNT, -1); }    

epoll_wait () will block if the file descriptor This is not an event to report about. In your case, I do not think you have reached epoll_wait () . Assuming that your program has passed connect () and accept () , then you have not written any data on the connection ( sockfd ), So do not detect any event at epoll_wait () connfd .

This is different from your first program, where you write a byte before calling pipefd [1] before epoll_wait () Pipefd [0] .

No comments:

Post a Comment