diff --git a/.travis.yml b/.travis.yml index 42bad2f..eef8bf9 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,13 +1,10 @@ language: c compiler: - gcc -before_install: sudo apt-get install check splint -install: - # Deal with issue on Travis builders - # https://github.com/travis-ci/travis-cookbooks/issues/155 - - "sudo rm -rf /dev/shm && sudo ln -s /run/shm /dev/shm" +addons: + apt: + packages: + - check + - splint script: ./autogen.sh && ./configure && make check && make distcheck -notifications: - email: - recipients: - - quarterback-devel@lists.fedorahosted.org +sudo: false diff --git a/README.markdown b/README.markdown index b8bedc0..2f2b130 100644 --- a/README.markdown +++ b/README.markdown @@ -1,49 +1,49 @@ # libqb ## What is libqb? -libqb is a library with the primary purpose of providing high performance -client server reusable features. It provides high performance logging, -tracing, ipc, and poll. +libqb is a library with the primary purpose of providing high-performance, +reusable features for client-server architecture, such as logging, +tracing, inter-process communication (IPC), and polling. -We don't intend be an all encompassing library, but instead provide very -specially focused APIs that are highly tuned for maximum performance for client/server applications. +libqb is not intended to be an all-encompassing library, but instead provide +focused APIs that are highly tuned for maximum performance for client-server +applications. [![Build Status](https://travis-ci.org/ClusterLabs/libqb.png)](https://travis-ci.org/ClusterLabs/libqb) -## For more information look at: -* [Our wiki](https://github.com/clusterlabs/libqb/wiki) +## For more information, see: +* [libqb wiki](https://github.com/clusterlabs/libqb/wiki) * [Issues/Bugs](https://github.com/clusterlabs/libqb/issues) * [The doxygen generated manual](http://clusterlabs.github.io/libqb/0.16.0/doxygen/) * You can build it yourself with the following commands: $ make doxygen $ firefox ./doc/html/index.html ## Dependencies * glib-2.0-devel (If you want to build the glib example code) * check-devel (If you want to run the tests) * doxygen and graphviz (If you want to build the doxygen man pages or html manual) ## Source Control (GIT) git clone git://github.com/ClusterLabs/libqb.git [See Github](https://github.com/clusterlabs/libqb) ## Installing from source $ ./autogen.sh $ ./configure $ make $ sudo make install ## How you can help If you find this project useful, you may want to consider supporting its future development. There are a number of ways to support the project. * Test and report issues. -* Help others on the [mailing list](https://fedorahosted.org/mailman/listinfo/quarterback-devel). +* Help others on the [developers@clusterlabs.org mailing list](http://clusterlabs.org/mailman/listinfo/developers). * Contribute documentation, examples and test cases. * Contribute patches. * Spread the word. - diff --git a/lib/Makefile.am b/lib/Makefile.am index 37b9c23..c153d7e 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -1,86 +1,86 @@ # # Copyright (C) 2010 Red Hat, Inc. # # Author: Angus Salkeld # # This file is part of libqb. # # libqb is free software: you can redistribute it and/or modify # it under the terms of the GNU Lesser General Public License as published by # the Free Software Foundation, either version 2.1 of the License, or # (at your option) any later version. # # libqb is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Lesser General Public License for more details. # # You should have received a copy of the GNU Lesser General Public License # along with libqb. If not, see . MAINTAINERCLEANFILES = Makefile.in noinst_HEADERS = ipc_int.h util_int.h ringbuffer_int.h loop_int.h \ log_int.h map_int.h rpl_sem.h loop_poll_int.h \ atomic_int.h AM_CPPFLAGS = -I$(top_builddir)/include -I$(top_srcdir)/include lib_LTLIBRARIES = libqb.la -libqb_la_LDFLAGS = -version-number 0:17:1 +libqb_la_LDFLAGS = -version-info 17:2:17 source_to_lint = util.c hdb.c ringbuffer.c ringbuffer_helper.c \ array.c loop.c loop_poll.c loop_job.c \ loop_timerlist.c ipcc.c ipcs.c ipc_shm.c \ ipc_setup.c ipc_socket.c \ log.c log_thread.c log_blackbox.c log_file.c \ log_syslog.c log_dcs.c log_format.c \ map.c skiplist.c hashtable.c trie.c libqb_la_SOURCES = $(source_to_lint) unix.c libqb_la_LIBADD = @LTLIBOBJS@ AM_LDFLAGS = $(LDFLAGS_COPY:-Bsymbolic-functions=) if HAVE_SEM_TIMEDWAIT else libqb_la_SOURCES+=rpl_sem.c endif if HAVE_EPOLL libqb_la_SOURCES+=loop_poll_epoll.c else if HAVE_KQUEUE libqb_la_SOURCES+=loop_poll_kqueue.c else libqb_la_SOURCES+=loop_poll_poll.c endif endif pkgconfigdir = $(libdir)/pkgconfig pkgconfig_DATA = libqb.pc if HAVE_SPLINT check_SCRIPTS = run_splint.sh TESTS = $(check_SCRIPTS) # this is a hack because debian/ubuntu don't set the arch path # in splint. DEB_INCLUDES = -I/usr/include/x86_64-linux-gnu -I/usr/include/i386-linux-gnu ALL_LINT_FLAGS = $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(DEB_INCLUDES) \ $(libqb_la_CPPFLAGS) $(CPPFLAGS) $(AM_CPPFLAGS) \ $(LINT_FLAGS) run_splint.sh: $(top_srcdir)/configure.ac echo "$(SPLINT) $(ALL_LINT_FLAGS) $(addprefix $(top_srcdir)/lib/, $(source_to_lint))" > $@ $(AM_V_GEN)chmod +x $@ dist-clean-local: $(AM_V_GEN)rm -f run_splint.sh clean-generic: $(AM_V_GEN)rm -f run_splint.sh endif diff --git a/lib/ipcc.c b/lib/ipcc.c index f9042c8..77ec3c3 100644 --- a/lib/ipcc.c +++ b/lib/ipcc.c @@ -1,451 +1,453 @@ /* * Copyright (C) 2010 Red Hat, Inc. * * Author: Angus Salkeld * * This file is part of libqb. * * libqb is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation, either version 2.1 of the License, or * (at your option) any later version. * * libqb is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with libqb. If not, see . */ #include "os_base.h" #include "ipc_int.h" #include "util_int.h" #include #include qb_ipcc_connection_t * qb_ipcc_connect(const char *name, size_t max_msg_size) { int32_t res; qb_ipcc_connection_t *c = NULL; struct qb_ipc_connection_response response; c = calloc(1, sizeof(struct qb_ipcc_connection)); if (c == NULL) { return NULL; } c->setup.max_msg_size = QB_MAX(max_msg_size, sizeof(struct qb_ipc_connection_response)); (void)strlcpy(c->name, name, NAME_MAX); res = qb_ipcc_us_setup_connect(c, &response); if (res < 0) { goto disconnect_and_cleanup; } c->response.type = response.connection_type; c->request.type = response.connection_type; c->event.type = response.connection_type; c->setup.type = response.connection_type; c->response.max_msg_size = response.max_msg_size; c->request.max_msg_size = response.max_msg_size; c->event.max_msg_size = response.max_msg_size; c->receive_buf = calloc(1, response.max_msg_size); c->fc_enable_max = 1; if (c->receive_buf == NULL) { res = -ENOMEM; goto disconnect_and_cleanup; } switch (c->request.type) { case QB_IPC_SHM: res = qb_ipcc_shm_connect(c, &response); break; case QB_IPC_SOCKET: res = qb_ipcc_us_connect(c, &response); break; case QB_IPC_POSIX_MQ: case QB_IPC_SYSV_MQ: res = -ENOTSUP; break; default: res = -EINVAL; break; } if (res != 0) { goto disconnect_and_cleanup; } c->is_connected = QB_TRUE; return c; disconnect_and_cleanup: - qb_ipcc_us_sock_close(c->setup.u.us.sock); + if (c->setup.u.us.sock >= 0) { + qb_ipcc_us_sock_close(c->setup.u.us.sock); + } free(c->receive_buf); free(c); errno = -res; return NULL; } static int32_t _check_connection_state_with(struct qb_ipcc_connection * c, int32_t res, struct qb_ipc_one_way * one_way, int32_t ms_timeout, int32_t events) { if (res >= 0) return res; if (qb_ipc_us_sock_error_is_disconnected(res)) { errno = -res; qb_util_perror(LOG_DEBUG, "interpreting result %d as a disconnect", res); c->is_connected = QB_FALSE; } if (res == -EAGAIN || res == -ETIMEDOUT) { int32_t res2; int32_t poll_ms = ms_timeout; if (res == -ETIMEDOUT) { poll_ms = 0; } res2 = qb_ipc_us_ready(one_way, &c->setup, poll_ms, events); if (qb_ipc_us_sock_error_is_disconnected(res2)) { errno = -res2; qb_util_perror(LOG_DEBUG, "%s %d %s", "interpreting result", res2, "(from socket) as a disconnect"); c->is_connected = QB_FALSE; res = res2; } else if (res != -ETIMEDOUT) { /* if the result we're checking against is a TIMEOUT error. * don't override that result with another error that does * not imply a disconnect */ res = res2; } } return res; } static int32_t _check_connection_state(struct qb_ipcc_connection * c, int32_t res) { if (res >= 0) return res; if (qb_ipc_us_sock_error_is_disconnected(res)) { errno = -res; qb_util_perror(LOG_DEBUG, "interpreting result %d as a disconnect", res); c->is_connected = QB_FALSE; } return res; } static struct qb_ipc_one_way * _event_sock_one_way_get(struct qb_ipcc_connection * c) { if (c->needs_sock_for_poll) { return &c->setup; } return &c->event; } static struct qb_ipc_one_way * _response_sock_one_way_get(struct qb_ipcc_connection * c) { if (c->needs_sock_for_poll) { return &c->setup; } return &c->response; } ssize_t qb_ipcc_send(struct qb_ipcc_connection * c, const void *msg_ptr, size_t msg_len) { ssize_t res; ssize_t res2; if (c == NULL) { return -EINVAL; } if (msg_len > c->request.max_msg_size) { return -EMSGSIZE; } if (c->funcs.fc_get) { res = c->funcs.fc_get(&c->request); if (res < 0) { return res; } else if (res > 0 && res <= c->fc_enable_max) { return -EAGAIN; } else { /* * we can transmit */ } } res = c->funcs.send(&c->request, msg_ptr, msg_len); if (res == msg_len && c->needs_sock_for_poll) { do { res2 = qb_ipc_us_send(&c->setup, msg_ptr, 1); } while (res2 == -EAGAIN); if (res2 == -EPIPE) { res2 = -ENOTCONN; } if (res2 != 1) { res = res2; } } return _check_connection_state(c, res); } int32_t qb_ipcc_fc_enable_max_set(struct qb_ipcc_connection * c, uint32_t max) { if (c == NULL || max > 2) { return -EINVAL; } c->fc_enable_max = max; return 0; } ssize_t qb_ipcc_sendv(struct qb_ipcc_connection * c, const struct iovec * iov, size_t iov_len) { int32_t total_size = 0; int32_t i; int32_t res; int32_t res2; for (i = 0; i < iov_len; i++) { total_size += iov[i].iov_len; } if (c == NULL) { return -EINVAL; } if (total_size > c->request.max_msg_size) { return -EMSGSIZE; } if (c->funcs.fc_get) { res = c->funcs.fc_get(&c->request); if (res < 0) { return res; } else if (res > 0 && res <= c->fc_enable_max) { return -EAGAIN; } else { /* * we can transmit */ } } res = c->funcs.sendv(&c->request, iov, iov_len); if (res > 0 && c->needs_sock_for_poll) { do { res2 = qb_ipc_us_send(&c->setup, &res, 1); } while (res2 == -EAGAIN); if (res2 == -EPIPE) { res2 = -ENOTCONN; } if (res2 != 1) { res = res2; } } return _check_connection_state(c, res); } ssize_t qb_ipcc_recv(struct qb_ipcc_connection * c, void *msg_ptr, size_t msg_len, int32_t ms_timeout) { int32_t res = 0; int32_t connect_res = 0; if (c == NULL) { return -EINVAL; } res = c->funcs.recv(&c->response, msg_ptr, msg_len, ms_timeout); if (res >= 0) { return res; } /* if we didn't get a msg, check connection state */ connect_res = _check_connection_state_with(c, res, _response_sock_one_way_get(c), ms_timeout, POLLIN); /* only report the connection state check result if an error is returned. */ if (connect_res < 0) { return connect_res; } return res; } ssize_t qb_ipcc_sendv_recv(qb_ipcc_connection_t * c, const struct iovec * iov, uint32_t iov_len, void *res_msg, size_t res_len, int32_t ms_timeout) { ssize_t res = 0; int32_t timeout_now; int32_t timeout_rem = ms_timeout; if (c == NULL) { return -EINVAL; } if (c->funcs.fc_get) { res = c->funcs.fc_get(&c->request); if (res < 0) { return res; } else if (res > 0 && res <= c->fc_enable_max) { return -EAGAIN; } else { /* * we can transmit */ } } res = qb_ipcc_sendv(c, iov, iov_len); if (res < 0) { return res; } do { if (timeout_rem > QB_IPC_MAX_WAIT_MS || ms_timeout == -1) { timeout_now = QB_IPC_MAX_WAIT_MS; } else { timeout_now = timeout_rem; } res = qb_ipcc_recv(c, res_msg, res_len, timeout_now); if (res == -ETIMEDOUT) { if (ms_timeout < 0) { res = -EAGAIN; } else { timeout_rem -= timeout_now; if (timeout_rem > 0) { res = -EAGAIN; } } } else if (res < 0 && res != -EAGAIN) { errno = -res; qb_util_perror(LOG_DEBUG, "qb_ipcc_recv %d timeout:(%d/%d)", res, timeout_now, timeout_rem); } } while (res == -EAGAIN && c->is_connected); return res; } int32_t qb_ipcc_fd_get(struct qb_ipcc_connection * c, int32_t * fd) { if (c == NULL) { return -EINVAL; } if (c->event.type == QB_IPC_SOCKET) { *fd = c->event.u.us.sock; } else { *fd = c->setup.u.us.sock; } return 0; } ssize_t qb_ipcc_event_recv(struct qb_ipcc_connection * c, void *msg_pt, size_t msg_len, int32_t ms_timeout) { char one_byte = 1; int32_t res; ssize_t size; if (c == NULL) { return -EINVAL; } res = _check_connection_state_with(c, -EAGAIN, _event_sock_one_way_get(c), ms_timeout, POLLIN); if (res < 0) { return res; } size = c->funcs.recv(&c->event, msg_pt, msg_len, ms_timeout); if (size > 0 && c->needs_sock_for_poll) { res = qb_ipc_us_recv(&c->setup, &one_byte, 1, -1); if (res != 1) { size = res; } } return _check_connection_state(c, size); } void qb_ipcc_disconnect(struct qb_ipcc_connection *c) { struct qb_ipc_one_way *ow = NULL; qb_util_log(LOG_DEBUG, "%s()", __func__); if (c == NULL) { return; } ow = _event_sock_one_way_get(c); (void)_check_connection_state_with(c, -EAGAIN, ow, 0, POLLIN); if (c->funcs.disconnect) { c->funcs.disconnect(c); } free(c->receive_buf); free(c); } void qb_ipcc_context_set(struct qb_ipcc_connection *c, void *context) { if (c == NULL) { return; } c->context = context; } void *qb_ipcc_context_get(struct qb_ipcc_connection *c) { if (c == NULL) { return NULL; } return c->context; } int32_t qb_ipcc_is_connected(qb_ipcc_connection_t *c) { struct qb_ipc_one_way *ow; if (c == NULL) { return QB_FALSE; } ow = _response_sock_one_way_get(c); (void)_check_connection_state_with(c, -EAGAIN, ow, 0, POLLIN); return c->is_connected; } int32_t qb_ipcc_get_buffer_size(qb_ipcc_connection_t * c) { if (c == NULL) { return -EINVAL; } return c->event.max_msg_size; } diff --git a/libqb.spec.in b/libqb.spec.in index 2d904f6..1e42ac5 100644 --- a/libqb.spec.in +++ b/libqb.spec.in @@ -1,72 +1,73 @@ %global alphatag @alphatag@ %global numcomm @numcomm@ %global dirty @dirty@ Name: libqb Version: @version@ Release: 1%{?numcomm:.%{numcomm}}%{?alphatag:.%{alphatag}}%{?dirty:.%{dirty}}%{?dist} Summary: An IPC library for high performance servers. Group: System Environment/Libraries License: LGPLv2+ URL: https://github.com/ClusterLabs/libqb Source0: https://fedorahosted.org/releases/q/u/quarterback/%{name}-%{version}%{?numcomm:.%{numcomm}}%{?alphatag:-%{alphatag}}%{?dirty:-%{dirty}}.tar.gz BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n) BuildRequires: autoconf automake libtool doxygen procps check-devel %description -libqb provides high performance client server reusable features. -Initially these are IPC and poll. +libqb provides high-performance, reusable features for client-server +architecture, such as logging, tracing, inter-process communication (IPC), +and polling. %prep %setup -q -n %{name}-%{version}%{?numcomm:.%{numcomm}}%{?alphatag:-%{alphatag}}%{?dirty:-%{dirty}} %build ./autogen.sh %configure --disable-static make %{?_smp_mflags} %check make check %install rm -rf $RPM_BUILD_ROOT make install DESTDIR=$RPM_BUILD_ROOT find $RPM_BUILD_ROOT -name '*.la' -exec rm -f {} ';' rm -rf $RPM_BUILD_ROOT/%{_datadir}/doc/libqb %clean rm -rf $RPM_BUILD_ROOT %post -p /sbin/ldconfig %postun -p /sbin/ldconfig %files %defattr(-,root,root,-) %doc COPYING %{_sbindir}/qb-blackbox %{_libdir}/libqb.so.* %package devel Summary: Development files for %{name} Group: Development/Libraries Requires: %{name} = %{version}-%{release} pkgconfig %description devel The %{name}-devel package contains libraries and header files for developing applications that use %{name}. %files devel %defattr(-,root,root,-) %doc COPYING README.markdown %{_includedir}/qb/ %{_libdir}/libqb.so %{_libdir}/pkgconfig/libqb.pc %{_mandir}/man3/qb*3* %{_mandir}/man8/qb-blackbox.8.gz %changelog * @date@ Autotools generated version - @version@-1-@numcomm@.@alphatag@.@dirty@ - Autotools generated version