Version 0.7.1. Small fix in usock_recv function.
parent
7eeda65cd9
commit
556652418a
24
Makefile
24
Makefile
|
@ -1,5 +1,5 @@
|
||||||
PACKAGE = 'libipc'
|
PACKAGE = 'libipc'
|
||||||
VERSION = '0.6.0'
|
VERSION = '0.7.1'
|
||||||
|
|
||||||
PREFIX := /usr/local
|
PREFIX := /usr/local
|
||||||
BINDIR := $(PREFIX)/bin
|
BINDIR := $(PREFIX)/bin
|
||||||
|
@ -50,25 +50,25 @@ libipc.so: src/communication.o src/context.o src/error.o src/fs.o src/message.o
|
||||||
$(Q)$(CC) -o libipc.so -shared $(LDFLAGS) src/communication.o src/context.o src/error.o src/fs.o src/message.o src/network.o src/print.o src/service_path.o src/usocket.o src/utils.o
|
$(Q)$(CC) -o libipc.so -shared $(LDFLAGS) src/communication.o src/context.o src/error.o src/fs.o src/message.o src/network.o src/print.o src/service_path.o src/usocket.o src/utils.o
|
||||||
|
|
||||||
libipc.so.install: libipc.so
|
libipc.so.install: libipc.so
|
||||||
@echo '[01;31m IN > [01;37m$(LIBDIR)/libipc.so.0.6.0[00m'
|
@echo '[01;31m IN > [01;37m$(LIBDIR)/libipc.so.0.7.1[00m'
|
||||||
$(Q)mkdir -p '$(DESTDIR)$(LIBDIR)'
|
$(Q)mkdir -p '$(DESTDIR)$(LIBDIR)'
|
||||||
$(Q)install -m0755 libipc.so $(DESTDIR)$(LIBDIR)/libipc.so.0.6.0
|
$(Q)install -m0755 libipc.so $(DESTDIR)$(LIBDIR)/libipc.so.0.7.1
|
||||||
@echo '[01;35m LN > [01;37m$(LIBDIR)/libipc.so.0.6[00m'
|
@echo '[01;35m LN > [01;37m$(LIBDIR)/libipc.so.0.7[00m'
|
||||||
$(Q)ln -sf '$(LIBDIR)/libipc.so.0.6.0' '$(DESTDIR)/$(LIBDIR)/libipc.so.0.6'
|
$(Q)ln -sf '$(LIBDIR)/libipc.so.0.7.1' '$(DESTDIR)/$(LIBDIR)/libipc.so.0.7'
|
||||||
@echo '[01;35m LN > [01;37m$(LIBDIR)/libipc.so.0[00m'
|
@echo '[01;35m LN > [01;37m$(LIBDIR)/libipc.so.0[00m'
|
||||||
$(Q)ln -sf '$(LIBDIR)/libipc.so.0.6.0' '$(DESTDIR)/$(LIBDIR)/libipc.so.0'
|
$(Q)ln -sf '$(LIBDIR)/libipc.so.0.7.1' '$(DESTDIR)/$(LIBDIR)/libipc.so.0'
|
||||||
@echo '[01;35m LN > [01;37m$(LIBDIR)/libipc.so[00m'
|
@echo '[01;35m LN > [01;37m$(LIBDIR)/libipc.so[00m'
|
||||||
$(Q)ln -sf '$(LIBDIR)/libipc.so.0.6.0' '$(DESTDIR)/$(LIBDIR)/libipc.so'
|
$(Q)ln -sf '$(LIBDIR)/libipc.so.0.7.1' '$(DESTDIR)/$(LIBDIR)/libipc.so'
|
||||||
|
|
||||||
libipc.so.clean:
|
libipc.so.clean:
|
||||||
@echo '[01;37m RM > [01;37mlibipc.so[00m'
|
@echo '[01;37m RM > [01;37mlibipc.so[00m'
|
||||||
$(Q)rm -f libipc.so
|
$(Q)rm -f libipc.so
|
||||||
|
|
||||||
libipc.so.uninstall:
|
libipc.so.uninstall:
|
||||||
@echo '[01;37m RM > [01;37m$(LIBDIR)/libipc.so.0.6.0[00m'
|
@echo '[01;37m RM > [01;37m$(LIBDIR)/libipc.so.0.7.1[00m'
|
||||||
$(Q)rm -f '$(DESTDIR)$(LIBDIR)/libipc.so.0.6.0'
|
$(Q)rm -f '$(DESTDIR)$(LIBDIR)/libipc.so.0.7.1'
|
||||||
@echo '[01;37m RM > [01;37m$(LIBDIR)/libipc.so.0.6[00m'
|
@echo '[01;37m RM > [01;37m$(LIBDIR)/libipc.so.0.7[00m'
|
||||||
$(Q)rm -f '$(DESTDIR)$(LIBDIR)/libipc.so.0.6'
|
$(Q)rm -f '$(DESTDIR)$(LIBDIR)/libipc.so.0.7'
|
||||||
@echo '[01;37m RM > [01;37m$(LIBDIR)/libipc.so.0[00m'
|
@echo '[01;37m RM > [01;37m$(LIBDIR)/libipc.so.0[00m'
|
||||||
$(Q)rm -f '$(DESTDIR)$(LIBDIR)/libipc.so.0'
|
$(Q)rm -f '$(DESTDIR)$(LIBDIR)/libipc.so.0'
|
||||||
@echo '[01;37m RM > [01;37m$(LIBDIR)/libipc.so[00m'
|
@echo '[01;37m RM > [01;37m$(LIBDIR)/libipc.so[00m'
|
||||||
|
@ -327,7 +327,7 @@ $(PACKAGE)-$(VERSION).tar.bz2: distdir
|
||||||
$(PACKAGE)-$(VERSION)/src/utils.h
|
$(PACKAGE)-$(VERSION)/src/utils.h
|
||||||
|
|
||||||
help:
|
help:
|
||||||
@echo '[01;37m :: libipc-0.6.0[00m'
|
@echo '[01;37m :: libipc-0.7.1[00m'
|
||||||
@echo ''
|
@echo ''
|
||||||
@echo '[01;37mGeneric targets:[00m'
|
@echo '[01;37mGeneric targets:[00m'
|
||||||
@echo '[00m - [01;32mhelp [37m Prints this help message.[00m'
|
@echo '[00m - [01;32mhelp [37m Prints this help message.[00m'
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
|
|
||||||
package=libipc # Package name.
|
package=libipc # Package name.
|
||||||
version=0.7.0 # Package version.
|
version=0.7.1 # Package version.
|
||||||
|
|
||||||
# Our targets are the library and its documentation.
|
# Our targets are the library and its documentation.
|
||||||
targets=(libipc man/libipc.7)
|
targets=(libipc man/libipc.7)
|
||||||
|
|
|
@ -35,37 +35,51 @@ struct ipc_error usock_recv (const int32_t fd, char **buf, size_t * len)
|
||||||
T_R ((buf == NULL), IPC_ERROR_USOCK_RECV__NO_BUFFER);
|
T_R ((buf == NULL), IPC_ERROR_USOCK_RECV__NO_BUFFER);
|
||||||
T_R ((len == NULL), IPC_ERROR_USOCK_RECV__NO_LENGTH);
|
T_R ((len == NULL), IPC_ERROR_USOCK_RECV__NO_LENGTH);
|
||||||
|
|
||||||
|
// printf("USOCKET: listen to %d (up to %lu bytes)\n", fd, *len);
|
||||||
int32_t ret_recv = 0;
|
int32_t ret_recv = 0;
|
||||||
|
|
||||||
if (*len == 0)
|
if (*len == 0)
|
||||||
*len = IPC_MAX_MESSAGE_SIZE;
|
*len = IPC_MAX_MESSAGE_SIZE;
|
||||||
|
|
||||||
|
// msize_read: size of the message (without the header).
|
||||||
uint32_t msize = 0;
|
uint32_t msize = 0;
|
||||||
|
|
||||||
|
// msize_read: size sum of the packets received.
|
||||||
uint32_t msize_read = 0;
|
uint32_t msize_read = 0;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
|
/**
|
||||||
|
* recv:
|
||||||
|
* ret > 0: message receveid
|
||||||
|
* ret == 0: fd is closing
|
||||||
|
* ret < 0: error
|
||||||
|
*/
|
||||||
ret_recv = recv (fd, *buf, *len, 0);
|
ret_recv = recv (fd, *buf, *len, 0);
|
||||||
#ifdef IPC_DEBUG
|
|
||||||
if (ret_recv > 0) {
|
if (ret_recv > 0) {
|
||||||
|
#ifdef IPC_DEBUG
|
||||||
print_hexa ("msg recv", (uint8_t *) * buf, ret_recv);
|
print_hexa ("msg recv", (uint8_t *) * buf, ret_recv);
|
||||||
fflush (stdout);
|
fflush (stdout);
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (ret_recv > 0) {
|
|
||||||
if (msize == 0) {
|
if (msize == 0) {
|
||||||
memcpy (&msize, *buf + 1, sizeof msize);
|
memcpy (&msize, *buf + 1, sizeof msize);
|
||||||
|
msize = ntohl (msize);
|
||||||
}
|
}
|
||||||
msize = ntohl (msize);
|
// else {
|
||||||
|
// printf ("USOCKET: We received a message in (at least) two packets (receveid %u bytes).\n", msize_read);
|
||||||
|
// }
|
||||||
|
|
||||||
if (msize >= IPC_MAX_MESSAGE_SIZE) {
|
if (msize > IPC_MAX_MESSAGE_SIZE) {
|
||||||
#ifdef IPC_DEBUG
|
#ifdef IPC_DEBUG
|
||||||
print_hexa ("msg recv", (uint8_t *) * buf, ret_recv);
|
print_hexa ("msg recv", (uint8_t *) * buf, ret_recv);
|
||||||
fflush (stdout);
|
fflush (stdout);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Do not allow messages with a longer size than expected.
|
||||||
T_R ((msize > IPC_MAX_MESSAGE_SIZE), IPC_ERROR_USOCK_RECV__MESSAGE_SIZE);
|
T_R ((msize > IPC_MAX_MESSAGE_SIZE), IPC_ERROR_USOCK_RECV__MESSAGE_SIZE);
|
||||||
msize_read += ret_recv - IPC_HEADER_SIZE;
|
|
||||||
|
msize_read += ret_recv;
|
||||||
} else if (ret_recv < 0) {
|
} else if (ret_recv < 0) {
|
||||||
*len = 0;
|
*len = 0;
|
||||||
|
|
||||||
|
@ -111,11 +125,17 @@ struct ipc_error usock_recv (const int32_t fd, char **buf, size_t * len)
|
||||||
, "usock_recv: recv < 0, is the message size malformed?");
|
, "usock_recv: recv < 0, is the message size malformed?");
|
||||||
}
|
}
|
||||||
|
|
||||||
} while (msize > msize_read);
|
// if (msize > msize_read) {
|
||||||
|
// printf ("USOCKET: loop again for %d (read %u/%u)\n", fd, msize_read, msize);
|
||||||
|
// }
|
||||||
|
|
||||||
*len = msize + IPC_HEADER_SIZE;
|
// In case msize still is 0, recv didn't worked as expected.
|
||||||
|
} while (msize > 0 && msize > msize_read - IPC_HEADER_SIZE);
|
||||||
|
|
||||||
// 1 on none byte received, indicates a closed recipient
|
// printf("USOCKET: end of the loop for client %d -- %u bytes read\n", fd, msize_read);
|
||||||
|
*len = msize_read;
|
||||||
|
|
||||||
|
// none bytes received, indicates a closed recipient
|
||||||
if (ret_recv == 0) {
|
if (ret_recv == 0) {
|
||||||
*len = 0;
|
*len = 0;
|
||||||
IPC_RETURN_ERROR (IPC_ERROR_CLOSED_RECIPIENT);
|
IPC_RETURN_ERROR (IPC_ERROR_CLOSED_RECIPIENT);
|
||||||
|
|
Reference in New Issue