ry / ebb fork watch download tarball
public this repo is viewable by everyone
Description: web server
Homepage: http://ebb.rubyforge.org
Clone URL: git://github.com/ry/ebb.git
python supports unix sockets and arbitrary fd
ryah (author)
about 1 month ago
commit  0861921e11e6cc5211d59ad13fd3471e85270b7a
tree    4fa60ceb6ee48ad12e0851b8fabb88bc0a1f277a
parent  cbef11050d5cde7478f45abe5f5bd3f97923f933
...
68
69
70
71
72
 
 
 
 
 
 
 
 
73
74
75
 
 
 
 
 
 
76
77
78
79
...
68
69
70
 
 
71
72
73
74
75
76
77
78
79
 
 
80
81
82
83
84
85
86
 
87
88
0
@@ -68,11 +68,20 @@ def request_cb(app, client):
0
   
0
   
0
 def start_server(app, args = {}):
0
- if args['port']:
0
- ebb_ffi.listen_on_port(int(args['port']))
0
+ if args.has_key('unix_socket'):
0
+ socketfile = args['unix_socket']
0
+ ebb_ffi.listen_on_unix_socket(socketfile)
0
+ print "Ebb is listening on unix socket %s" % socketfile
0
+ elif args.has_key('fileno'):
0
+ fileno = int(args['fileno'])
0
+ ebb_ffi.listen_on_fd(fileno)
0
+ print "Ebb is listening on fd %d" % fileno
0
   else:
0
- print "no port given!"
0
- exit(1)
0
+ if args.has_key('port'):
0
+ port = int(args['port'])
0
+ else:
0
+ port = 4001
0
+ ebb_ffi.listen_on_port(port)
0
+ print "Ebb is listening at http://0.0.0.0:%d/" % port
0
   
0
- print "Ebb listening on port %d" % args['port']
0
   ebb_ffi.process_connections(app, request_cb)
0
\ No newline at end of file
...
264
265
266
 
 
 
 
 
 
267
268
269
270
271
272
 
273
274
275
276
277
 
278
279
 
 
 
 
 
 
 
 
 
 
 
280
281
282
283
284
 
 
285
286
287
...
264
265
266
267
268
269
270
271
272
273
274
275
 
 
 
276
277
278
279
280
 
281
282
 
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
0
@@ -264,24 +264,40 @@ static PyObject *process_connections(PyObject *_, PyObject *args)
0
   Py_RETURN_NONE;
0
 }
0
 
0
+static PyObject *server_stop(PyObject *_)
0
+{
0
+ server_running = FALSE;
0
+ Py_RETURN_NONE;
0
+}
0
+
0
 static PyObject *listen_on_port(PyObject *_, PyObject *args)
0
 {
0
   int port;
0
- if(!PyArg_ParseTuple(args, "i", &port))
0
- return NULL;
0
- ebb_server_init(&server, loop, request_cb, NULL);
0
+ if(!PyArg_ParseTuple(args, "i", &port)) return NULL;
0
   ebb_server_listen_on_port(&server, port);
0
   Py_RETURN_NONE;
0
 }
0
 
0
-static PyObject *server_stop(PyObject *_)
0
+static PyObject *listen_on_fd(PyObject *_, PyObject *args)
0
 {
0
- server_running = FALSE;
0
+ int fd;
0
+ if(!PyArg_ParseTuple(args, "i", &fd)) return NULL;
0
+ ebb_server_listen_on_fd(&server, fd);
0
+ Py_RETURN_NONE;
0
+}
0
+
0
+static PyObject *listen_on_unix_socket(PyObject *_, PyObject *args)
0
+{
0
+ char *socketfile;
0
+ if(!PyArg_ParseTuple(args, "s", &socketfile)) return NULL;
0
+ ebb_server_listen_on_unix_socket(&server, socketfile);
0
   Py_RETURN_NONE;
0
 }
0
 
0
 static PyMethodDef ebb_module_methods[] =
0
   { {"listen_on_port", (PyCFunction)listen_on_port, METH_VARARGS, NULL}
0
+ , {"listen_on_fd", (PyCFunction)listen_on_fd, METH_VARARGS, NULL}
0
+ , {"listen_on_unix_socket", (PyCFunction)listen_on_unix_socket, METH_VARARGS, NULL}
0
   , {"process_connections", (PyCFunction)process_connections, METH_VARARGS, NULL}
0
   , {"server_stop", (PyCFunction)server_stop, METH_NOARGS, NULL}
0
   , {NULL, NULL, 0, NULL}
...
10
11
12
13
14
 
15
...
10
11
12
 
13
14
15
0
@@ -10,4 +10,4 @@ def simple_app(environ):
0
   body = ["Hello world!\n"]
0
   return([status, headers, body])
0
 
0
-ebb.start_server(simple_app, {'port': 4001})
0
\ No newline at end of file
0
+ebb.start_server(simple_app, {'unix_socket': '/tmp/ebb.sock'})
0
\ No newline at end of file

Comments

    No one has commented yet.