3 # This is a make+ file. Make+ is a set of scripts which enhance GNU
4 # make and let you build RPMs, and other package types with just one
5 # control file. To build this package you will need to download make+
6 # from this site: http://www.annexia.org/freeware/makeplus/
11 VERSION := $(VERSION_MAJOR).$(VERSION_MINOR)
13 SUMMARY := small, fast, efficient server library for C
15 AUTHOR := Richard W.M. Jones <rich@annexia.org>
18 pthrlib is a library for writing small, fast and efficient servers in
19 C. It offers a list of advanced features. This library has been used
20 to write a very tiny and fast web server called rws and a closed
21 source chat server. All functions are documented in manual pages, and
22 example servers are included.
25 RPM_REQUIRES := c2lib >= 1.4.0, postgresql-devel >= 7.1
26 RPM_GROUP := Development/Libraries
28 CFLAGS += -Wall -Werror -g -O2 -I$(includedir)/c2lib
29 ifeq (1,$(HAVE_PG_CONFIG))
30 CFLAGS += -I$(shell pg_config --includedir)
32 ifneq ($(shell uname), SunOS)
33 # Avoid a warning about reordering system include paths.
34 CFLAGS += $(shell pcre-config --cflags)
37 ifeq (1,$(HAVE_PG_CONFIG))
38 LIBS += -L$(shell pg_config --libdir) -lpq
40 LIBS += $(shell pcre-config --libs) -lm
42 OBJS := src/pthr_cgi.o src/pthr_context.o src/pthr_dbi.o \
43 src/pthr_ftpc.o src/pthr_http.o src/pthr_iolib.o \
44 src/pthr_listener.o src/pthr_mutex.o \
45 src/pthr_pseudothread.o src/pthr_reactor.o \
46 src/pthr_rwlock.o src/pthr_server.o src/pthr_stack.o \
48 LOBJS := $(OBJS:.o=.lo)
50 HEADERS := $(srcdir)/src/pthr_cgi.h $(srcdir)/src/pthr_context.h \
51 $(srcdir)/src/pthr_dbi.h $(srcdir)/src/pthr_ftpc.h \
52 $(srcdir)/src/pthr_http.h $(srcdir)/src/pthr_iolib.h \
53 $(srcdir)/src/pthr_listener.h $(srcdir)/src/pthr_mutex.h \
54 $(srcdir)/src/pthr_pseudothread.h \
55 $(srcdir)/src/pthr_reactor.h \
56 $(srcdir)/src/pthr_rwlock.h $(srcdir)/src/pthr_server.h \
57 $(srcdir)/src/pthr_stack.h $(srcdir)/src/pthr_wait_queue.h
62 @pg_config --version || \
63 ( echo "PostgreSQL must be installed - make sure PATH" \
64 "contains pg bin directory"; exit 1 )
66 $(MP_REQUIRE_LIB) pmap c2lib
67 $(MP_CHECK_PROG) pg_config
68 $(MP_CHECK_LIB) PQconnectStart pq
69 $(MP_CHECK_HEADERS) alloca.h arpa/inet.h assert.h \
70 ctype.h dirent.h errno.h \
71 execinfo.h fcntl.h grp.h libpq-fe.h netdb.h \
72 netinet/in.h netinet/ip.h netinet/ip_icmp.h postgresql/libpq-fe.h \
73 pwd.h setjmp.h signal.h string.h syslog.h sys/mman.h sys/poll.h \
74 sys/socket.h sys/stat.h sys/syslimits.h sys/time.h sys/types.h \
75 sys/uio.h sys/wait.h \
76 time.h ucontext.h unistd.h
77 $(MP_CHECK_FUNCS) backtrace getenv gettimeofday gmtime putenv setenv \
78 socket strftime syslog time unsetenv PQescapeString
79 $(srcdir)/conf/test_setcontext.sh
82 build: static dynamic examples/pthr_eg1_echo examples/pthr_eg2_server \
85 # Build the static library.
87 static: src/libpthrlib.a
89 src/libpthrlib.a: $(OBJS)
90 $(MP_LINK_STATIC) $@ $^
92 # Build the dynamic library.
94 dynamic: src/libpthrlib.so
96 src/libpthrlib.so: $(LOBJS)
97 $(MP_LINK_DYNAMIC) $@ $^ $(LIBS)
101 $(CC) $(CFLAGS) -I../src -c $< -o $@
103 # Build dynamic object files.
105 $(CC) $(CFLAGS) -fPIC -I../src -c $< -o $@
107 # Build the example programs.
109 examples/pthr_eg1_echo: examples/pthr_eg1_echo.o examples/pthr_eg1_echo_main.o
110 $(CC) $(CFLAGS) $^ -o $@ -Lsrc -lpthrlib $(LIBS)
112 examples/pthr_eg2_server: examples/pthr_eg2_server.o \
113 examples/pthr_eg2_server_main.o
114 $(CC) $(CFLAGS) $^ -o $@ -Lsrc -lpthrlib $(LIBS)
116 # Build object files.
117 examples/%.o: examples/%.c
118 $(CC) $(CFLAGS) -I../src -c $< -o $@
120 # Build the manual pages.
122 manpages: $(srcdir)/src/*.h
126 --author '$(AUTHOR)' \
127 --license '$(COPYRIGHT)' \
128 --version '$(PACKAGE)-$(VERSION)' \
132 # Build the symbols table.
134 syms: src/libpthrlib.syms
136 src/libpthrlib.syms: src/libpthrlib.so
137 nm $< | sort | grep -i '^[0-9a-f]' | awk '{print $$1 " " $$3}' > $@
139 test: src/test_context src/test_reactor src/test_pseudothread src/test_select \
140 src/test_bigstack src/test_except1 src/test_except2 src/test_except3 \
141 src/test_mutex src/test_rwlock src/test_dbi
142 LD_LIBRARY_PATH=src:$(LD_LIBRARY_PATH) $(MP_RUN_TESTS) $^
144 src/test_context: src/test_context.o
145 $(CC) $(CFLAGS) $^ -o $@ -Lsrc -lpthrlib $(LIBS)
146 src/test_reactor: src/test_reactor.o
147 $(CC) $(CFLAGS) $^ -o $@ -Lsrc -lpthrlib $(LIBS)
148 src/test_pseudothread: src/test_pseudothread.o
149 $(CC) $(CFLAGS) $^ -o $@ -Lsrc -lpthrlib $(LIBS)
150 src/test_select: src/test_select.o
151 $(CC) $(CFLAGS) $^ -o $@ -Lsrc -lpthrlib $(LIBS)
152 src/test_bigstack: src/test_bigstack.o
153 $(CC) $(CFLAGS) $^ -o $@ -Lsrc -lpthrlib $(LIBS)
154 src/test_except1: src/test_except1.o
155 $(CC) $(CFLAGS) $^ -o $@ -Lsrc -lpthrlib $(LIBS)
156 src/test_except2: src/test_except2.o
157 $(CC) $(CFLAGS) $^ -o $@ -Lsrc -lpthrlib $(LIBS)
158 src/test_except3: src/test_except3.o
159 $(CC) $(CFLAGS) $^ -o $@ -Lsrc -lpthrlib $(LIBS)
160 src/test_mutex: src/test_mutex.o
161 $(CC) $(CFLAGS) $^ -o $@ -Lsrc -lpthrlib $(LIBS)
162 src/test_rwlock: src/test_rwlock.o
163 $(CC) $(CFLAGS) $^ -o $@ -Lsrc -lpthrlib $(LIBS)
164 src/test_dbi: src/test_dbi.o
165 $(CC) $(CFLAGS) $^ -o $@ -Lsrc -lpthrlib $(LIBS)
168 install -d $(DESTDIR)$(libdir)
169 install -d $(DESTDIR)$(includedir)
170 install -d $(DESTDIR)$(man3dir)
171 install -d $(DESTDIR)$(datadir)/rws/symtabs/
172 install -d $(DESTDIR)$(bindir)
174 $(MP_INSTALL_STATIC_LIB) src/libpthrlib.a
175 $(MP_INSTALL_DYNAMIC_LIB) src/libpthrlib.so
177 install -m 0644 $(HEADERS) $(DESTDIR)$(includedir)
178 install -m 0644 *.3 $(DESTDIR)$(man3dir)
179 install -m 0644 src/*.syms $(DESTDIR)$(datadir)/rws/symtabs/
180 install -m 0755 examples/pthr_eg1_echo examples/pthr_eg2_server \
184 <% include page_header.msp %>
186 <h1>$(PACKAGE) - $(SUMMARY)</h1>
189 <tt>pthrlib</tt> is a library for writing small, fast and efficient
190 servers in C. It offers a list of advanced features (see below).
191 This library has been used to write a very tiny and fast
192 <a href="../rws/">web server called rws</a> and
193 a closed source chat server. All functions are documented in
194 manual pages, and example servers are included.
198 It contains the following features:
202 <li> <i>reactor & pseudothreads</i>: underpinning
203 the whole library is a lightweight cooperative threading
204 library written on top of a Reactor pattern. Typically
205 you can create of the order of thousands of threads
206 (the number of threads is generally limited by other
207 things like how many file descriptors your C library
208 supports -- assuming each thread is handling one client
209 over one socket). Pseudothreads support thread
210 listings and throw/catch-style exception handling.
211 <li> <i>iolib</i>: a buffered I/O library written
212 on top of the pseudothread "syscalls".
213 <li> <i>http</i>: a library for writing HTTP/1.1
214 RFC-compliant servers.
215 <li> <i>cgi</i>: a library for writing CGI scripts
216 in C which run inside the server [new in pthrlib 2.0.1].
217 <li> <i>dbi</i>: a PostgreSQL database interface,
218 modelled on Perl's DBI. Includes connection pooling
219 [new in pthrlib 3.0.8].
220 <li> <i>wait_queue</i>: synchronize between threads
221 using wait queues (several threads go to sleep on
222 the wait queue until some point later when another
223 thread wakes them all up).
224 <li> <i>mutex, rwlock</i>: simple mutual exclusion
225 locks and multiple-reader/single-writer locks.
226 <li> <i>listener</i>: a thread class which listens
227 for connections on a given port and throws off
228 threads to process them.
229 <li> <i>ftpc</i>: an FTP client library.
233 <a href="doc/">There is extensive documentation and
246 <td> <a href="$(PACKAGE)-$(VERSION).tar.gz">$(PACKAGE)-$(VERSION).tar.gz</a> </td>
248 <td> Latest source distribution </td>
251 <td> <a href="$(PACKAGE)-$(VERSION)-1.i686.rpm">$(PACKAGE)-$(VERSION)-1.i686.rpm</a> </td>
252 <td> i686 binary RPM </td>
253 <td> Binary development libraries, header files, man pages
254 for Red Hat Linux </td>
257 <td> <a href="$(PACKAGE)-$(VERSION)-1.src.rpm">$(PACKAGE)-$(VERSION)-1.src.rpm</a> </td>
258 <td> source RPM </td>
259 <td> Source files for Red Hat Linux </td>
264 This library requires <a href="../c2lib/">c2lib</a>.
265 To rebuild the manual pages which come with the
266 package, you will also need to download the
267 <a href="../c2lib/">cdoc</a> program. Since
268 3.2.0, pthrlib requires the <a href="../makeplus/">make+</a>
273 <a href="/cgi-bin/autopatch.pl?dir=pthrlib">Patches between versions
280 <b>Sat Feb 1 2003:</b>
281 Updated README and INSTALL files. Updated
282 <code>Makefile+</code> to work with the new
283 version of make+. Ported to FreeBSD 5.0.
284 Added connection pooling to pthr_dbi library.
285 <strong>NB: The RPMs were built on Debian and may not work on Red Hat
289 <b>Sat Feb 8 17:00:47 GMT 2003:</b>
290 Ported to Solaris, OpenBSD and FreeBSD (thanks to
291 <a href="http://www.azazel.net/">Jeremy Sowden</a>
292 and <a href="http://www.mondaymorning.org/">Richard Baker</a>
293 for help and equipment). Updated to work with gcc 3.2 (multi-line
294 strings are now deprecated). Fixed for RH 7.3.
298 <b>Sun Dec 8 13:44:32 GMT 2002:</b>
299 Major API change: <code>current_pth</code> contains
300 the current thread. A lot of functions which took
301 <code>pth</code> as a parameter now no longer need
302 these parameter. Fixed <code>io_popen</code> to
303 call <code>_exit</code> instead of <code>exit</code>
304 so that the registered <code>atexit</code> functions
305 aren't called incorrectly in the child process.
306 Fixed <code>pth_wait_writable</code>, <code>pth_wait_readable</code>.
307 Updated to use <a href="../makeplus/">make+</a>.
308 Enabled debugging and optimisations.
309 Fixes to compile on RH 7.3.
313 <b>Mon Nov 25 09:31:37 GMT 2002:</b>
314 Added symbols file for full symbol resolution in monolith.
315 Catch segfaults and dump a stack trace.
316 Added <code>mutex_nr_sleepers</code> function.
320 <b>Sun Nov 17 23:31:32 GMT 2002:</b> Debian packages. Added MSP
321 files. Added patches to enabled chunked encoding (thanks to
322 Steve Atkins). Fixes to compile on RH 7.3. Support for
323 <code>DBI_TIMESTAMP</code>, <code>DBI_INTERVAL</code>,
324 <code>DBI_INT_OR_NULL</code>, <code>DBI_CHAR</code>,
325 <code>DBI_BOOL</code> in the
326 DBI library. Better handling of NULLs in the DBI library.
331 <b>Thu Nov 14 15:33:29 GMT 2002:</b> Major checkpoint release
336 <b>Sun Oct 20 14:46:46 BST 2002:</b> Support for cookies.
337 Get last serial number from an <code>INSERT</code>.
338 DBI now correctly handles nulls in execute statements.
339 Fixed elusive bugs in <code>pth_wait_readable</code> and
340 <code>pth_wait_writable</code> which were causing monolith
341 to crash. Optimisation to wait queues which also removes
342 a crashing bug in monolith.
346 <b>Tue Oct 15 23:40:42 BST 2002:</b> Multiple bug fixes.
350 <b>Sun Oct 13 18:47:41 BST 2002:</b> Patch to
351 disable test_dbi code if no DBI configured.
352 Added <code>pthr_server_default_address</code>
353 and <code>pthr_server_address_option</code> which
354 allows the server to listen on a single interface
355 instead of on <code>INADDR_ANY</code>.
356 (Both patches thanks to Steve Atkins - steve at blighty com).
360 <b>Sun Oct 13 12:55:08 BST 2002:</b> Added a
361 complete PostgreSQL database interface library,
362 similar to the Perl DBI. See <code>src/test_dbi.c</code>
363 for example usage. This requires
364 <a href="../c2lib/">c2lib >= 1.2.21</a>.
368 <b>Wed Oct 9 19:10:38 BST 2002:</b> Added
369 <code>http_request_set_url</code> method which
370 is used by <a href="../rws/">rws</a> to update
371 the URL during internal rewrites.
375 <b>Sat Sep 7 15:38:33 BST 2002:</b> Packages are now
376 available as i686 binary RPMs and source RPMs.
379 <h2>Old news and old versions</h2>
382 <b>Sat Aug 31 14:53:52 BST 2002</b>
386 <a href="pthrlib-3.0.4.tar.gz">pthrlib-3.0.4.tar.gz</a>
387 released. This contains a complete tutorial and some
392 <b>Fri Aug 23 15:00:51 BST 2002</b>
396 <a href="pthrlib-3.0.3.tar.gz">pthrlib-3.0.3.tar.gz</a>
397 released. This adds the <code>copy_cgi</code> and
398 <code>cgi_erase</code> functions required by
399 <a href="../monolith/">monolith</a>.
403 <b>Thu Aug 22 13:20:32 BST 2002</b>
407 <a href="pthrlib-3.0.2.tar.gz">pthrlib-3.0.2.tar.gz</a>
409 This includes manual pages which were accidentally omitted
410 from the previous version.
414 <b>Wed Aug 21 14:20:12 BST 2002</b>
418 <a href="pthrlib-3.0.1.tar.gz">pthrlib-3.0.1.tar.gz</a>
419 fixes a few silly bugs which stopped the new version
420 of <a href="../rws/">rws</a> from working.
424 <b>Wed Aug 21 11:59:17 BST 2002</b>
428 <a href="pthrlib-3.0.0.tar.gz">pthrlib-3.0.0.tar.gz</a>
429 released. This version replaces the old
430 <code>pthr_server_main</code> function with a newer, simpler
431 <code>pthr_server_main_loop</code> function. The
432 <code>pthr_listener</code> thread code has been modified
433 slightly to allow multiple listeners to run at the same time
434 (necessary for Fleet). This breaks a lot of old code, hence the
435 major version number increase. All the included examples
436 have been changed to support the new interface.
440 <b>Fri Nov 16 10:43:00 GMT 2001</b>
444 <a href="pthrlib-2.2.1.tar.gz">pthrlib-2.2.1.tar.gz</a> released.
445 A few bug fixes for glibc 2.2.4. You will need to use this
446 version if you are using Red Hat Linux 7.x.
450 <b>Mon Jul 9 07:43:07 BST 2001</b>
454 <a href="pthrlib-2.2.0.tar.gz">pthrlib-2.2.0.tar.gz</a> released.
455 Added an FTP client library.
459 <b>Fri Jun 15 15:46:10 BST 2001</b>
463 <a href="pthrlib-2.1.6.tar.gz">pthrlib-2.1.6.tar.gz</a> released.
464 Stack support improved: stack overflows cause core dumps
465 rather than random memory corruption; stacks are
466 stored in memory mapped regions so they don't take memory
467 unless you actually use them; stack size is configurable
468 at run time. HTTP library uses
469 exceptions for error messages.
470 Support for profiling. Added a second example webserver.
471 Tests for exception handling code. Added API call to
472 allow you to count the number of threads running.
473 Documentation updates.
476 <b>Wed May 30 13:01:46 BST 2001</b>
480 <a href="pthrlib-2.1.0.tar.gz">pthrlib-2.1.0.tar.gz</a> released.
481 This has experimental support for throw/catch-style exception
482 handling. Please see the <code>pth_die(3)</code> and
483 <code>pth_catch(3)</code> manual pages for full details.
487 <b>Tue May 22 14:11:21 BST 2001</b>
491 <a href="pthrlib-2.0.5.tar.gz">pthrlib-2.0.5.tar.gz</a> released.
492 Backed out previous URL-escaping patch. The fix goes better
493 into <a href="../rws/">rws</a> instead.
497 <b>Tue May 22 11:37:10 BST 2001</b>
501 <a href="pthrlib-2.0.4.tar.gz">pthrlib-2.0.4.tar.gz</a> released.
502 URLs are now unescaped properly, allowing clients to correctly
503 request URLs like '/%7Euser/'.
507 <b>Tue Apr 10 16:04:41 BST 2001</b>
511 <a href="pthrlib-2.0.2.tar.gz">pthrlib-2.0.2.tar.gz</a> released.
512 Added support for generating logfiles.
516 <b>Mon Apr 9 17:23:59 BST 2001</b>
520 <a href="pthrlib-2.0.1.tar.gz">pthrlib-2.0.1.tar.gz</a> released.
521 The <i>http</i> library component in version 1.x has
522 been split more logically to support only the mechanics
523 of parsing HTTP connections. The CGI part of it (eg.
524 query string parsing, etc.) has been moved into a
525 new library called <i>cgi</i>. This necessarily breaks
526 older programs, hence the major version number
527 increase. There are some other minor changes and
528 bug fixes: the server name string can now be
529 changed; CGI.pm-like POST_MAX can be set; fixed
530 a really nasty bug in <i>iolib</i> -- it wasn't
531 setting the output buffering mode to the correct
532 default; fixed <code>io_popen(3)</code> so it can
533 handle the case where fds 0 and/or 1 are already
534 closed; added <code>io_copy(3)</code> function to
535 copy bytes between two file descriptors;
536 <code>pthr_server_main</code> now includes <code>sys/types.h</code>
541 <b>Mon Mar 26 13:05:42 BST 2001</b>
545 <a href="pthrlib-1.6.6.tar.gz">pthrlib-1.6.6.tar.gz</a> released.
546 Add <code>-lm</code> when linking with c2lib libraries.
551 <b>Mon Mar 12 12:12:49 GMT 2001</b>
555 <a href="pthrlib-1.6.5.tar.gz">pthrlib-1.6.5.tar.gz</a> released.
556 This fixes a bug in the way the library was calling
557 <code>pstrcat</code> (in <a href="../c2lib/">c2lib</a>).
558 Upgrading is highly recommended. You will also need
559 to upgrade to the latest <a href="../c2lib/">c2lib</a>.
564 <b>Fri Mar 9 17:32:13 GMT 2001</b>
568 <a href="pthrlib-1.6.4.tar.gz">pthrlib-1.6.4.tar.gz</a> released.
569 Unit test suite added which covers much of the functionality.
570 Fixed a nasty bug in <tt>io_popen</tt>. Fixed another nasty
571 bug in the pseudothread code. Fixed a false assertion in
572 the rwlock code (revealed during unit testing).
576 <b>Fri Feb 23 16:37:58 GMT 2001</b>
580 <a href="pthrlib-1.6.2.tar.gz">pthrlib-1.6.2.tar.gz</a> released.
581 <tt>pth_timeout</tt> function added and a nasty race condition
582 in the reactor (which affected wait queues) fixed.
586 <b>Fri Feb 16 18:02:46 GMT 2001</b>
590 <a href="pthrlib-1.6.1.tar.gz">pthrlib-1.6.1.tar.gz</a> released.
591 All functions are documented in manual pages.
594 <% include page_footer.msp %>
598 scp $(PACKAGE)-$(VERSION).tar.gz $(PACKAGE)-$(VERSION)-1.*.rpm \
599 $(PACKAGE)-$(VERSION).bin.tar.gz \
600 10.0.0.248:annexia.org/freeware/$(PACKAGE)/
602 10.0.0.248:annexia.org/freeware/$(PACKAGE)/index.msp
604 .PHONY: build configure test upload_website