From fe1cb3bbdb47567aecd87d1a9c23a303e09ec689 Mon Sep 17 00:00:00 2001 From: Georg Hopp Date: Mon, 22 Sep 2014 21:19:25 +0100 Subject: [PATCH] add possibility to just open a socket without bind or listen or connect --- Makefile.am | 9 ++++++++- include/tr/socket.h | 7 +++++-- src/socket_init.c | 2 +- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/Makefile.am b/Makefile.am index a7936ed..d5670a9 100644 --- a/Makefile.am +++ b/Makefile.am @@ -16,5 +16,12 @@ coverage-html: -$(MAKE) -C tests $(AM_MAKEFLAGS) -k $@ endif +REGEX_CCLASS=/^[ \t]*\(TR_CLASS\|TR_INTERFACE\)\(([a-zA-Z0-9_]+)/\2/d,definition/ tags: - ctags -R -V --langdef=cclass --langmap=cclass:.h --regex-cclass='/^[ \t]*\(TR_CLASS\|TR_INTERFACE\)\(([a-zA-Z0-9_]+)/\2/d,definition/' + @ctags -R -V --langdef=cclass --langmap=cclass:.h \ + --regex-cclass='$(REGEX_CCLASS)' + +loc: + @find src/ include/ -not -path testers -and -name "*.[ch]" \ + -exec sed '/\/\*/,/\*\//d;/\/\//d' {} \; | wc -l + diff --git a/include/tr/socket.h b/include/tr/socket.h index 018331a..6fb1457 100644 --- a/include/tr/socket.h +++ b/include/tr/socket.h @@ -139,14 +139,17 @@ TR_SocketFin TR_socketShutdown(TR_Socket); void TR_socketClose(TR_Socket); void TR_socketNonblock(TR_Socket); -#define TR_socketBind(socket) \ +#define TR_socketBind(socket) \ (TR_socketInit((socket), TR_socketBindAction)) TR_TcpSocket TR_socketAccept(TR_TcpSocket); -#define TR_socketConnect(socket) \ +#define TR_socketConnect(socket) \ (TR_socketInit((socket), TR_socketConnectAction)) +#define TR_socketOpen(socket) \ + (TR_socketInit((socket), NULL)) + #endif // __TR_SOCKET_H__ // vim: set ts=4 sw=4: diff --git a/src/socket_init.c b/src/socket_init.c index b582e54..f20dbdf 100644 --- a/src/socket_init.c +++ b/src/socket_init.c @@ -80,7 +80,7 @@ TR_socketInit(TR_Socket this, TR_socketAction_fptr action) this->addrlen = current_info->ai_addrlen; memcpy(&(this->addr), current_info->ai_addr, this->addrlen); - if (0 == action(this)) { + if (! action || 0 == action(this)) { break; // success / open and bind or open and connect... }