Linux libraries for developing. (It`s NOT finished yet!)
Change current dirctrory to QPHi, run ./build.sh help
that will show usage:
$ ./build.sh help
Usage:
./build.sh -- Release build.
./build.sh debug -- Debug build.
./build.sh install -- Install after build.
First, build the library:
$ ./build.sh
If you want build it with debug info:
$ ./build.sh debug
After that, run ./build.sh install
to install the library (may need sudo
):
$ sudo ./build.sh install
Socket module for TCP and Unix socket. (example: events.c, tcp_delay.c)
File module with general I/O and direct I/O.(example: pcapreader.c)
Simple event loop.(example: events.c)
Linux ipc wrapper.(example: lock.c)
Memory pool manager(example: events.c)
Process and thread manager.(example: lock.c)
System method wrapper.
Tiny tcp/ip stack implementations.(example: pcapreader.c)
There are also some examples showing how to use those libraries in QPHi/test
and QPHi/example
:
read_process:
qp_int_t
read_process(qp_int_t index, qp_event_stat_t stat, qp_uchar_t* cache, size_t offset)
{
if (QP_EVENT_CLOSE == stat || offset < 1) {
return QP_ERROR;
}
return 1;
}
write_process:
qp_int_t
write_process(qp_int_t index, qp_event_stat_t stat, qp_uchar_t* cache, \
size_t* write_bytes, size_t size)
{
*write_bytes = strlen(HTTP_RSP) > size ? size : strlen(HTTP_RSP);
strncpy(cache, HTTP_RSP, *write_bytes);
return 0; // close after writting
}
main:
int
main()
{
qp_event_t event;
qp_socket_t skt;
if (!(skt = qp_socket_init(NULL, AF_INET, SOCK_STREAM, "0.0.0.0", 8080, true,\
128)) || !(event = qp_event_init(NULL, 1024, true, true) ))
{
fprintf(stderr, "\n Socket or event init fail.");
goto end;
}
qp_event_regist_read_process_handler(event, read_process);
qp_event_regist_write_process_handler(event, write_process);
qp_socket_set_reuse(skt, QP_SOCKET_SO_REUSE_ADDR, 1);
if (QP_ERROR == qp_socket_listen(skt, 0)) {
fprintf(stderr, "\n Listen fail.");
goto end;
}
if (QP_ERROR == qp_event_addevent(event, qp_socket_to_int(skt), 30, true, false)) {
fprintf(stderr, "\n Add event fail.");
goto end;
}
qp_event_dispatch(event, 0);
end:
qp_socket_destroy(skt);
qp_event_destroy(event);
fprintf(stderr, "\n Quit.");
return 0;
}
QPHi is released under a MIT License.See LICENSE file for details.