-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
git-svn-id: http://evserver.googlecode.com/svn/trunk@2 e9bb6d7e-af12-11dd-bad7-87afd3b02348
- Loading branch information
majek04
committed
Nov 10, 2008
1 parent
c94e881
commit c9f8168
Showing
19 changed files
with
3,276 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
|
||
PYTHON=$(shell which python) | ||
|
||
CTYPESPY=evserver/ctypes_event.py | ||
LIBEVENTOUT=evserver/libevent.so | ||
|
||
.PHONY : clean all ctypes | ||
|
||
egg: eggs | ||
|
||
eggs: | ||
$(PYTHON) setup.py bdist_egg | ||
|
||
clean: | ||
find . -name "*.pyc" | xargs rm -f | ||
find . -name "*.pyo" | xargs rm -f | ||
rm -rf build dist evserver.egg-info | ||
rm -f $(CTYPESPY) $(LIBEVENTOUT) | ||
rm -f /tmp/fifo | ||
rm -f log | ||
|
||
# needs: | ||
# sudo apt-get install gccxml python-setuptools | ||
# sudo easy_install ctypeslib | ||
# libevent >= 1.4.2 compiled sources in LIBEVENTSOURCES | ||
# (1.4.1 has a bug in chunked encoding and requires patching) | ||
# libevent-1.4.6, libevent-1.4.7, libevent-1.4.8 *DON'T* work for me. | ||
# no time still to investigate where is the bug | ||
# for example: | ||
# cd /tmp/libevent | ||
# ./configure --prefix=/usr | ||
# make | ||
|
||
# use libevent sources, this will need the application to be runned with LD_LIBRARY_PATH | ||
ifndef LIBEVENTSOURCES | ||
ifeq (ok, $(shell [ -e "../libevent" ] && echo ok)) | ||
LIBEVENTSOURCES=../libevent | ||
endif | ||
ifeq (ok, $(shell [ -e "/tmp/libevent" ] && echo ok)) | ||
LIBEVENTSOURCES=/tmp/libevent | ||
endif | ||
endif | ||
|
||
LIBEVENTLIB=$(LIBEVENTSOURCES)/.libs | ||
LIBEVENTINCLUDE=$(LIBEVENTSOURCES) | ||
LIBEVENTPRELOAD=$(LIBEVENTLIB)/libevent.so | ||
|
||
|
||
# figuring this out was painful | ||
#$ :D_LIBRARY_PATH="." python -c "import ctypes; ctypes.CDLL('libevent.so')"; | ||
ctypes: | ||
@if [ ! -e "$(LIBEVENTPRELOAD)" ] ; then \ | ||
echo "Not found $(LIBEVENTPRELOAD). Check the libevent sources path in LIBEVENTSOURCES." ;\ | ||
echo "You should run: LIBEVENTSOURCES=../my/path/to/compiled/libevent make"; \ | ||
exit 1 ;\ | ||
fi | ||
@if [ ! -e "$(LIBEVENTINCLUDE)/http-internal.h" ] ; then \ | ||
echo "Not found $(LIBEVENTINCLUDE)/http-internal.h. Check the libevent sources path in LIBEVENTSOURCES." ;\ | ||
echo "You should run: LIBEVENTSOURCES=../my/path/to/compiled/libevent make"; \ | ||
exit 1 ;\ | ||
fi | ||
|
||
# testing dependencies | ||
@gccxml --version | ||
@python -c "import ctypeslib; import sys; sys.exit(0)" | ||
|
||
|
||
@echo "[*] preparing headers" | ||
cp $(LIBEVENTINCLUDE)/event.h . | ||
cp $(LIBEVENTINCLUDE)/http-internal.h . | ||
|
||
@echo "\ | ||
#ifndef TAILQ_ENTRY \n\ | ||
#define _EVENT_DEFINED_TQENTRY \n\ | ||
#define TAILQ_ENTRY(type) \\\\\n\ | ||
struct { \\\\\n\ | ||
struct type *tqe_next; /* next element */ \\\\\n\ | ||
struct type **tqe_prev; /* address of previous next element */ \\\\\n\ | ||
} \n\ | ||
#endif /* !TAILQ_ENTRY */ \n\ | ||
" > evhttp.h | ||
cat $(LIBEVENTINCLUDE)/evhttp.h >> evhttp.h | ||
|
||
@echo "\ | ||
extern \"C\" { \n\ | ||
#import <stdlib.h> \n\ | ||
#import <sys/queue.h> \n\ | ||
#import <sys/socket.h> \n\ | ||
#import \"event.h\" \n\ | ||
#import \"evhttp.h\" \n\ | ||
#import \"http-internal.h\" \n\ | ||
} \n\ | ||
" > d.h | ||
|
||
@echo "\ | ||
# don't touch. automatically generated by 'make ctypes' \n\ | ||
# for file $(LIBEVENTPRELOAD) \n\ | ||
import ctypes \n\ | ||
c_longdouble = ctypes.c_double \n\ | ||
" > $(CTYPESPY) | ||
|
||
@echo "[*] magick happens" --preload "$(LIBEVENTPRELOAD)" | ||
h2xml.py -I"$(LIBEVENTINCLUDE)" $(PWD)/d.h -o d.xml -q -c | ||
LD_LIBRARY_PATH=$(LIBEVENTLIB) xml2py.py -llibevent.so -d d.xml -r "(event_|signal_|evbuffer_|evhttp|evtimer|EV).*" >> $(CTYPESPY) | ||
# fix output | ||
sed -i "s/CDLL('libevent.so')/CDLL(libeventbinary)/g" $(CTYPESPY) | ||
|
||
@echo "[*] new bindings to libevent are in $(CTYPESPY)" | ||
cp $(LIBEVENTPRELOAD) $(LIBEVENTOUT) | ||
rm d.xml evhttp.h event.h http-internal.h d.h | ||
|
||
|
||
test: | ||
PYTHONPATH="." $(PYTHON) test.py | ||
|
||
prepare: clean ctypes | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
|
||
INSTALLATION | ||
|
||
You should probably check out current development brach: | ||
$ svn checkout http://evserver.googlecode.com/svn/trunk/ evserver | ||
|
||
Then, to use 'evserver' you just need to set your PYTHONPATH environment | ||
variable, for example, if you have evserver sources installed in your home directory: | ||
$ PYTHONPATH="$HOME/evserver" python ./myscript.py | ||
|
||
If you must have egg package, you can get one: | ||
$ wget "" | ||
$ sudo easy_install evserver | ||
|
||
But beware, this packet has included a libevent.so binary, which is 32 bits only. | ||
|
||
|
||
COMPILATION | ||
|
||
This package needs libevent.so binary and automatically generated python wrapper | ||
file for this specific version of libevent. Currently I include libevent 1.4.5 | ||
32 bit files. If you need to use your own version of libevent, you must: | ||
- install dependencies: | ||
$ sudo apt-get install gccxml python-setuptools | ||
$ sudo easy_install ctypeslib | ||
|
||
- grab libevent sources. Libevent from 1.4.2 to 1.4.5 seems to be working. 1.4.1 had | ||
an important bug in chunk encoding, 1.4.6 and newer have issues when receiving | ||
timeouts on file descriptors. I use libevent-1.4.5. | ||
You need to compile the sources. | ||
$ wget "http://monkey.org/~provos/libevent-1.4.5-stable.tar.gz" | ||
$ tar xvzf libevent-1.4.5-stable.tar.gz | ||
$ cd libevent-1.4.5 | ||
$ ./configure && make | ||
|
||
- Run 'make ctypes' with LIBEVENTSOURCES environment variable set, for example: | ||
$ LIBEVENTSOURCES=../libevent-1.4.5-stable make ctypes | ||
Then, if you need to create egg, just run 'make egg' | ||
$ LIBEVENTSOURCES=../libevent-1.4.5-stable make egg | ||
Your package will be ready in 'dist' directory. | ||
|
||
|
||
RUNNING | ||
|
||
If you installed egg just try: | ||
$ evserver | ||
|
||
If you haven't installed egg, only got the development branch in ~/evserver: | ||
$ ~/evserver/evserver.py | ||
|
||
|
||
TESTS | ||
|
||
There are some working tests for the application. You can run them: | ||
$ make test |
Empty file.
Oops, something went wrong.