Add non-closing lwevent_free()
This commit is contained in:
		
							parent
							
								
									cfcea63f7a
								
							
						
					
					
						commit
						27133a87ed
					
				|  | @ -47,11 +47,11 @@ struct lwevent* lwevent_new(int fd, int events, lwevent_callback callback) | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| /* lwevent_free()
 | /* lwevent_free_and_close()
 | ||||||
|  *  Mark `ev' as invalid, closing its file descriptor and calling the destructor (if there is one). |  *  Mark `ev' as invalid, closing its file descriptor and calling the destructor (if there is one). | ||||||
|  *  If the object is already invalid, or is null, do nothing. |  *  If the object is already invalid, or is null, do nothing. | ||||||
|  */ |  */ | ||||||
| void lwevent_free(struct lwevent* ev) | void lwevent_free_and_close(struct lwevent* ev) | ||||||
| { | { | ||||||
|     if(!ev || ev->fd == -1) return; |     if(!ev || ev->fd == -1) return; | ||||||
| 
 | 
 | ||||||
|  | @ -63,6 +63,24 @@ void lwevent_free(struct lwevent* ev) | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  | /* lwevent_free()
 | ||||||
|  |  *  Mark `ev' as invalid, calling the destructor (if there is one). If the object is already  | ||||||
|  |  *  invalid, or is null, do nothing. Also remove `ev->fd' from epoll's consideration. | ||||||
|  |  */ | ||||||
|  | void lwevent_free(struct lwevent* ev) | ||||||
|  | { | ||||||
|  |     int dummy; | ||||||
|  | 
 | ||||||
|  |     if(!ev || ev->fd == -1) return; | ||||||
|  | 
 | ||||||
|  |     /* call destructor, deregister from epoll, mark as invalid */ | ||||||
|  |     if(ev->dtor) ev->dtor(ev); | ||||||
|  |     dummy = lwevent_deactivate(ev); | ||||||
|  |     _lwevent_invalid(ev); | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
| /* lwevent_deactivate()
 | /* lwevent_deactivate()
 | ||||||
|  *  Temporarily deactivate `ev'. Calls epoll_ctl(EPOLL_CTL_DEL). |  *  Temporarily deactivate `ev'. Calls epoll_ctl(EPOLL_CTL_DEL). | ||||||
|  */ |  */ | ||||||
|  |  | ||||||
|  | @ -98,6 +98,20 @@ without consequence. At the end of the event loop, once no more callbacks are qu | ||||||
| objects are freed. This means that you cannot continue to refer to invalid objects after a completed | objects are freed. This means that you cannot continue to refer to invalid objects after a completed | ||||||
| call to lwevent_wait(). | call to lwevent_wait(). | ||||||
| 
 | 
 | ||||||
|  | */ | ||||||
|  | void lwevent_free_and_close(struct lwevent* ev); | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | /*! \brief Free an event structure.
 | ||||||
|  | 
 | ||||||
|  | \param ev Event structure. May be 0. | ||||||
|  | 
 | ||||||
|  | This function will call the registered destructor of \a ev (see \ref fdparams) and free any memory | ||||||
|  | used by \a ev. It may be called at any time in the event loop. If called with a null argument, it is | ||||||
|  | a no-op. The file descriptor associated with \a ev is not modified (but it is deregistered from the | ||||||
|  | event loop). | ||||||
|  | 
 | ||||||
| */ | */ | ||||||
| void lwevent_free(struct lwevent* ev); | void lwevent_free(struct lwevent* ev); | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue
	
	 Laurence Withers
						Laurence Withers