Commits

rickysu committed fc76f68

do not free buffer event with internal bufferevent

  • Participants
  • Parent commits 0c827e8

Comments (0)

Files changed (3)

classes/buffer_event.c

 				"Failed to allocate bufferevent for socket");
 		return;
 	}
-
+        bev->_internal = 0;
 	bev->bevent = bevent;
 
 	bev->self = zself;
 	PHP_EVENT_FETCH_BEVENT(bev, zbevent);
 
 	if (bev->bevent) {
-		bufferevent_free(bev->bevent);
+                if(!bev->_internal){
+		    bufferevent_free(bev->bevent);
+                }
 		bev->bevent = 0;
 
 		/* Do it once */
 		return;
 	}
 #endif
-	
+
 	if (family & ~(AF_INET | AF_INET6 | AF_UNSPEC)) {
 		php_error_docref(NULL TSRMLS_CC, E_WARNING,
 				"Invalid address family specified");
 
 	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "OZOl|l",
 				&zbase, php_event_base_ce,
-				&ppzfd, 
+				&ppzfd,
 				&zctx, php_event_ssl_context_ce,
 				&state, &options) == FAILURE) {
 		return;
 
 	e = bufferevent_get_openssl_error(bev->bevent);
 	if (e) {
-		RETURN_STRING(ERR_error_string(e, buf), 1);	
+		RETURN_STRING(ERR_error_string(e, buf), 1);
 	}
 
 	RETVAL_FALSE;

classes/http_request.c

 	zend_fcall_info_cache  fcc      = empty_fcall_info_cache;
 	zval                  *zarg     = NULL;
 	struct evhttp_request *req;
-	
+
 
 	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "f|z",
 				&fci, &fcc, &zarg) == FAILURE) {
 	bev->self = return_value;
 	Z_ADDREF_P(return_value);
 	bev->input = bev->output = NULL;
+        bev->_internal = 1;
 }
 /* }}} */
 
 /* }}} */
 
 /* {{{ proto void EventHttpRequest::sendReplyEnd(void);
- * Complete a chunked reply, freeing the request as appropriate. 
+ * Complete a chunked reply, freeing the request as appropriate.
  */
 PHP_METHOD(EventHttpRequest, sendReplyEnd)
 {
  *
  * Cancels an ongoing HTTP request. The callback associated with this request
  * is not executed and the request object is freed. If the request is currently
- * being processed, e.g. it is ongoing, the corresponding EventHttpConnection 
+ * being processed, e.g. it is ongoing, the corresponding EventHttpConnection
  * object is going to get reset.
  *
  * A request cannot be canceled if its callback has executed already. A request
 #ifndef PHP_EVENT_STRUCTS_H
 #define PHP_EVENT_STRUCTS_H
 
-/* Thread context. With it we are getting rid of need 
+/* Thread context. With it we are getting rid of need
  * to call the heavy TSRMLS_FETCH() */
 #ifdef ZTS
 # define PHP_EVENT_COMMON_THREAD_CTX void ***thread_ctx
 	PHP_EVENT_OBJECT_HEAD;
 
 	struct bufferevent    *bevent;
+        int                   _internal;
 	zval                  *self;        /* Object itself. For callbacks                   */
 	zval                  *data;        /* User custom data                               */
 	zval                  *input;       /* Input buffer */