Commits

Ruslan Osmanov  committed 3754ed1

Fix: return values of EventHttp::addServerAlias, EventHttp::removeServerAlias
Add: examples/http_alias.php
Fix: EventHttp::setDefaultCallback' arginfo

  • Participants
  • Parent commits 1f3db82

Comments (0)

Files changed (4)

File classes/http.c

 }
 /* }}} */
 
-/* {{{ proto void EventHttp::addServerAlias(string alias);
+/* {{{ proto bool EventHttp::addServerAlias(string alias);
  * Adds a server alias to the object.
  */
 PHP_METHOD(EventHttp, addServerAlias)
 
 	PHP_EVENT_FETCH_HTTP(http, zhttp);
 
-	evhttp_add_server_alias(http->ptr, alias);
+	if (evhttp_add_server_alias(http->ptr, alias)) {
+		RETURN_FALSE;
+	}
+	RETVAL_TRUE;
 }
 /* }}} */
 
-/* {{{ proto void EventHttp::removeServerAlias(string alias);
+/* {{{ proto bool EventHttp::removeServerAlias(string alias);
  * Removes a server alias from the object.
  */
 PHP_METHOD(EventHttp, removeServerAlias)
 
 	PHP_EVENT_FETCH_HTTP(http, zhttp);
 
-	evhttp_remove_server_alias(http->ptr, alias);
+	if (evhttp_remove_server_alias(http->ptr, alias)) {
+		RETURN_FALSE;
+	}
+	RETVAL_TRUE;
 }
 /* }}} */
 

File examples/http_alias.php

+<?php
+
+$base = new EventBase();
+$http = new EventHttp($base);
+
+$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
+
+if (!$http->bind("127.0.0.1", 8088)) {
+	exit("bind(1) failed\n");
+};
+
+if (!$http->addServerAlias("local.net")) {
+	exit("Failed to add server alias\n");
+}
+
+$http->setCallback("/about", function($req) {
+	echo "URI: ", $req->getUri(), PHP_EOL;
+	$req->sendReply(200, "OK");
+	echo "OK\n";
+});
+$base->dispatch();
+
+?>
     <email>osmanov@php.net</email>
     <active>yes</active>
   </lead>
-  <date>2013-03-10</date>
+  <date>2013-03-13</date>
   <!--{{{ Current version -->
   <version>
     <release>1.4.0</release>
         <file role="doc" name="eio.php"/>
         <file role="doc" name="fibonacci_buffer.php"/>
         <file role="doc" name="http.php"/>
+        <file role="doc" name="http_accept.php"/>
+        <file role="doc" name="http_alias.php"/>
+        <file role="doc" name="http_bind.php"/>
+        <file role="doc" name="http_request.php"/>
         <file role="doc" name="httpv0client.php"/>
         <file role="doc" name="httpv0client2.php"/>
         <file role="doc" name="listener.php"/>
 	ZEND_ARG_INFO(0, arg)
 ZEND_END_ARG_INFO();
 
+ZEND_BEGIN_ARG_INFO_EX(arginfo_event_http_set_gen_callback, 0, 0, 1)
+	ZEND_ARG_INFO(0, cb)
+	ZEND_ARG_INFO(0, arg)
+ZEND_END_ARG_INFO();
+
 ZEND_BEGIN_ARG_INFO_EX(arginfo_event_http_set_allowed_methods, 0, 0, 1)
 	ZEND_ARG_INFO(0, methods)
 ZEND_END_ARG_INFO();
 	PHP_ME(EventHttp, accept,             arginfo_event_http_accept,              ZEND_ACC_PUBLIC)
 	PHP_ME(EventHttp, bind,               arginfo_event_http_bind,                ZEND_ACC_PUBLIC)
 	PHP_ME(EventHttp, setCallback,        arginfo_event_http_set_callback,        ZEND_ACC_PUBLIC)
-	PHP_ME(EventHttp, setDefaultCallback, arginfo_event_http_set_callback,        ZEND_ACC_PUBLIC)
+	PHP_ME(EventHttp, setDefaultCallback, arginfo_event_http_set_gen_callback,    ZEND_ACC_PUBLIC)
 	PHP_ME(EventHttp, setAllowedMethods,  arginfo_event_http_set_allowed_methods, ZEND_ACC_PUBLIC)
 	PHP_ME(EventHttp, setMaxBodySize,     arginfo_event_http_set_value,           ZEND_ACC_PUBLIC)
 	PHP_ME(EventHttp, setMaxHeadersSize,  arginfo_event_http_set_value,           ZEND_ACC_PUBLIC)