Fix lwevent_set_events().
This function should only update the lwevent structure's event mask if the call to epoll_ctl() succeeds. This does, however, mean that the event mask cannot be changed if the lwevent instance is deactivated.
This commit is contained in:
		
							parent
							
								
									f8f6e4aa3b
								
							
						
					
					
						commit
						5ed8cef02f
					
				| 
						 | 
					@ -44,19 +44,29 @@ int lwevent_get_autodestroy(const struct lwevent* ev)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* lwevent_set_events()
 | 
					/* lwevent_set_events()
 | 
				
			||||||
 *  Calls epoll_ctl(EPOLL_CTL_MOD) to change the events associated with the object `ev'. Does not
 | 
					 *  Calls epoll_ctl(EPOLL_CTL_MOD) to change the events associated with the object `ev'. Does not
 | 
				
			||||||
 *  perform the call if the new events match the current events. If `old_events' is not null, stores
 | 
					 *  perform the call if the new events match the current events. Returns -1 if epoll_ctl fails.
 | 
				
			||||||
 *  the existing events before changing. Returns -1 if epoll_ctl fails.
 | 
					 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
int lwevent_set_events(struct lwevent* ev, int events)
 | 
					int lwevent_set_events(struct lwevent* ev, int events)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    if(events == ev->events) return 0; /* don't call epoll_ctl() if no change */
 | 
					    struct epoll_event ee;
 | 
				
			||||||
    return _lwevent_activate(EPOLL_CTL_MOD, ev);
 | 
					
 | 
				
			||||||
 | 
					    /* don't call epoll_ctl() if no change */
 | 
				
			||||||
 | 
					    if(events == ev->events) return 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /* try the modification */
 | 
				
			||||||
 | 
					    ee.events = events;
 | 
				
			||||||
 | 
					    ee.data.ptr = ev;
 | 
				
			||||||
 | 
					    if(TEMP_FAILURE_RETRY( epoll_ctl(lwevent_epoll_fd, EPOLL_CTL_MOD, ev->fd, &ee) )) return -1;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /* update structure only if it succeeded */
 | 
				
			||||||
 | 
					    ev->events = events;
 | 
				
			||||||
 | 
					    return 0;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
    
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* lwevent_set_*()
 | 
					/* lwevent_set_*()
 | 
				
			||||||
 *  Changes attributes associated with `ev', possibly storing the old value.
 | 
					 *  Changes attributes associated with `ev'.
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
void lwevent_set_callback(struct lwevent* ev, lwevent_callback callback)
 | 
					void lwevent_set_callback(struct lwevent* ev, lwevent_callback callback)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue