Archived
3
0

Version 0.7.1. Small fix in usock_recv function.

This commit is contained in:
Karchnu 2020-09-01 00:16:43 +02:00
parent 7eeda65cd9
commit 556652418a
3 changed files with 43 additions and 23 deletions

View File

@ -1,5 +1,5 @@
PACKAGE = 'libipc'
VERSION = '0.6.0'
VERSION = '0.7.1'
PREFIX := /usr/local
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
libipc.so.install: libipc.so
@echo ' IN > $(LIBDIR)/libipc.so.0.6.0'
@echo ' IN > $(LIBDIR)/libipc.so.0.7.1'
$(Q)mkdir -p '$(DESTDIR)$(LIBDIR)'
$(Q)install -m0755 libipc.so $(DESTDIR)$(LIBDIR)/libipc.so.0.6.0
@echo ' LN > $(LIBDIR)/libipc.so.0.6'
$(Q)ln -sf '$(LIBDIR)/libipc.so.0.6.0' '$(DESTDIR)/$(LIBDIR)/libipc.so.0.6'
$(Q)install -m0755 libipc.so $(DESTDIR)$(LIBDIR)/libipc.so.0.7.1
@echo ' LN > $(LIBDIR)/libipc.so.0.7'
$(Q)ln -sf '$(LIBDIR)/libipc.so.0.7.1' '$(DESTDIR)/$(LIBDIR)/libipc.so.0.7'
@echo ' LN > $(LIBDIR)/libipc.so.0'
$(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 ' LN > $(LIBDIR)/libipc.so'
$(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:
@echo ' RM > libipc.so'
$(Q)rm -f libipc.so
libipc.so.uninstall:
@echo ' RM > $(LIBDIR)/libipc.so.0.6.0'
$(Q)rm -f '$(DESTDIR)$(LIBDIR)/libipc.so.0.6.0'
@echo ' RM > $(LIBDIR)/libipc.so.0.6'
$(Q)rm -f '$(DESTDIR)$(LIBDIR)/libipc.so.0.6'
@echo ' RM > $(LIBDIR)/libipc.so.0.7.1'
$(Q)rm -f '$(DESTDIR)$(LIBDIR)/libipc.so.0.7.1'
@echo ' RM > $(LIBDIR)/libipc.so.0.7'
$(Q)rm -f '$(DESTDIR)$(LIBDIR)/libipc.so.0.7'
@echo ' RM > $(LIBDIR)/libipc.so.0'
$(Q)rm -f '$(DESTDIR)$(LIBDIR)/libipc.so.0'
@echo ' RM > $(LIBDIR)/libipc.so'
@ -327,7 +327,7 @@ $(PACKAGE)-$(VERSION).tar.bz2: distdir
$(PACKAGE)-$(VERSION)/src/utils.h
help:
@echo ' :: libipc-0.6.0'
@echo ' :: libipc-0.7.1'
@echo ''
@echo 'Generic targets:'
@echo ' - help  Prints this help message.'

View File

@ -1,6 +1,6 @@
package=libipc # Package name.
version=0.7.0 # Package version.
version=0.7.1 # Package version.
# Our targets are the library and its documentation.
targets=(libipc man/libipc.7)

View File

@ -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 ((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;
if (*len == 0)
*len = IPC_MAX_MESSAGE_SIZE;
// msize_read: size of the message (without the header).
uint32_t msize = 0;
// msize_read: size sum of the packets received.
uint32_t msize_read = 0;
do {
/**
* recv:
* ret > 0: message receveid
* ret == 0: fd is closing
* ret < 0: error
*/
ret_recv = recv (fd, *buf, *len, 0);
#ifdef IPC_DEBUG
if (ret_recv > 0) {
#ifdef IPC_DEBUG
print_hexa ("msg recv", (uint8_t *) * buf, ret_recv);
fflush (stdout);
}
#endif
if (ret_recv > 0) {
if (msize == 0) {
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
print_hexa ("msg recv", (uint8_t *) * buf, ret_recv);
fflush (stdout);
#endif
}
// Do not allow messages with a longer size than expected.
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) {
*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?");
}
} 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) {
*len = 0;
IPC_RETURN_ERROR (IPC_ERROR_CLOSED_RECIPIENT);