mirror of
https://github.com/servalproject/serval-dna.git
synced 2025-01-18 02:39:44 +00:00
Issue #20: improve new socket function logging
__whence argument and function macros
This commit is contained in:
parent
498eba2051
commit
7453e82a27
26
serval.h
26
serval.h
@ -168,16 +168,24 @@ int create_serval_instance_dir();
|
|||||||
int form_serval_instance_path(char *buf, size_t bufsiz, const char *path);
|
int form_serval_instance_path(char *buf, size_t bufsiz, const char *path);
|
||||||
void serval_setinstancepath(const char *instancepath);
|
void serval_setinstancepath(const char *instancepath);
|
||||||
|
|
||||||
/* Create a named socket using abstract socket on Linux or a local socket on
|
/* Basic socket operations.
|
||||||
* other platforms.
|
|
||||||
*/
|
*/
|
||||||
int esocket(int domain, int type, int protocol);
|
int _esocket(struct __sourceloc __whence, int domain, int type, int protocol);
|
||||||
int socket_setname(struct sockaddr_un *sockname, const char *name, socklen_t *addrlen);
|
int _socket_setname(struct __sourceloc __whence, struct sockaddr_un *sockname, const char *name, socklen_t *addrlen);
|
||||||
int socket_bind(int sock, const struct sockaddr *addr, socklen_t addrlen);
|
int _socket_bind(struct __sourceloc __whence, int sock, const struct sockaddr *addr, socklen_t addrlen);
|
||||||
int socket_connect(int sock, const struct sockaddr *addr, socklen_t addrlen);
|
int _socket_connect(struct __sourceloc __whence, int sock, const struct sockaddr *addr, socklen_t addrlen);
|
||||||
int socket_listen(int sock, int backlog);
|
int _socket_listen(struct __sourceloc __whence, int sock, int backlog);
|
||||||
int socket_set_reuseaddr(int fd, int reuseP);
|
int _socket_set_reuseaddr(struct __sourceloc __whence, int sock, int reuseP);
|
||||||
int socket_set_rcvbufsize(int fd, unsigned buffer_size);
|
int _socket_set_rcvbufsize(struct __sourceloc __whence, int sock, unsigned buffer_size);
|
||||||
|
|
||||||
|
#define esocket(domain, type, protocol) _esocket(__HERE__, domain, type, protocol)
|
||||||
|
#define socket_setname(sockname, name, addrlenp) _socket_setname(__HERE__, sockname, name, addrlenp)
|
||||||
|
#define socket_bind(sock, addr, addrlen) _socket_bind(__HERE__, sock, addr, addrlen)
|
||||||
|
#define socket_connect(sock, addr, addrlen) _socket_connect(__HERE__, sock, addr, addrlen)
|
||||||
|
#define socket_listen(sock, backlog) _socket_listen(__HERE__, sock, backlog)
|
||||||
|
#define socket_set_reuseaddr(sock, reuseP) _socket_set_reuseaddr(__HERE__, sock, reuseP)
|
||||||
|
#define socket_set_rcvbufsize(sock, buffer_size) _socket_set_rcvbufsize(__HERE__, sock, buffer_size)
|
||||||
|
|
||||||
|
|
||||||
#define SERVER_CONFIG_RELOAD_INTERVAL_MS 1000
|
#define SERVER_CONFIG_RELOAD_INTERVAL_MS 1000
|
||||||
|
|
||||||
|
14
socket.c
14
socket.c
@ -31,7 +31,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|||||||
* @author Andrew Bettison <andrew@servalproject.com>
|
* @author Andrew Bettison <andrew@servalproject.com>
|
||||||
* @author Daniel O'Connor <daniel@servalproject.com>
|
* @author Daniel O'Connor <daniel@servalproject.com>
|
||||||
*/
|
*/
|
||||||
int socket_setname(struct sockaddr_un *addr, const char *name, socklen_t *addrlen)
|
int _socket_setname(struct __sourceloc __whence, struct sockaddr_un *addr, const char *name, socklen_t *addrlen)
|
||||||
{
|
{
|
||||||
bzero(addr, sizeof(*addr));
|
bzero(addr, sizeof(*addr));
|
||||||
addr->sun_family = AF_UNIX;
|
addr->sun_family = AF_UNIX;
|
||||||
@ -49,7 +49,7 @@ int socket_setname(struct sockaddr_un *addr, const char *name, socklen_t *addrle
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int esocket(int domain, int type, int protocol)
|
int _esocket(struct __sourceloc __whence, int domain, int type, int protocol)
|
||||||
{
|
{
|
||||||
int fd;
|
int fd;
|
||||||
if ((fd = socket(AF_UNIX, SOCK_STREAM, 0)) == -1)
|
if ((fd = socket(AF_UNIX, SOCK_STREAM, 0)) == -1)
|
||||||
@ -59,7 +59,7 @@ int esocket(int domain, int type, int protocol)
|
|||||||
return fd;
|
return fd;
|
||||||
}
|
}
|
||||||
|
|
||||||
int socket_connect(int sock, const struct sockaddr *addr, socklen_t addrlen)
|
int _socket_connect(struct __sourceloc __whence, int sock, const struct sockaddr *addr, socklen_t addrlen)
|
||||||
{
|
{
|
||||||
if (connect(sock, (struct sockaddr *)addr, addrlen) == -1)
|
if (connect(sock, (struct sockaddr *)addr, addrlen) == -1)
|
||||||
return WHYF_perror("connect(%d,%s,%lu)", sock, alloca_sockaddr(addr, addrlen), (unsigned long)addrlen);
|
return WHYF_perror("connect(%d,%s,%lu)", sock, alloca_sockaddr(addr, addrlen), (unsigned long)addrlen);
|
||||||
@ -68,7 +68,7 @@ int socket_connect(int sock, const struct sockaddr *addr, socklen_t addrlen)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int socket_bind(int sock, const struct sockaddr *addr, socklen_t addrlen)
|
int _socket_bind(struct __sourceloc __whence, int sock, const struct sockaddr *addr, socklen_t addrlen)
|
||||||
{
|
{
|
||||||
if (addr->sa_family == AF_UNIX && ((struct sockaddr_un *)addr)->sun_path[0]) {
|
if (addr->sa_family == AF_UNIX && ((struct sockaddr_un *)addr)->sun_path[0]) {
|
||||||
if (unlink(((struct sockaddr_un *)addr)->sun_path) == -1 && errno != ENOENT)
|
if (unlink(((struct sockaddr_un *)addr)->sun_path) == -1 && errno != ENOENT)
|
||||||
@ -83,7 +83,7 @@ int socket_bind(int sock, const struct sockaddr *addr, socklen_t addrlen)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int socket_listen(int sock, int backlog)
|
int _socket_listen(struct __sourceloc __whence, int sock, int backlog)
|
||||||
{
|
{
|
||||||
if (listen(sock, backlog) == -1)
|
if (listen(sock, backlog) == -1)
|
||||||
return WHYF_perror("listen(%d,%d)", sock, backlog);
|
return WHYF_perror("listen(%d,%d)", sock, backlog);
|
||||||
@ -92,7 +92,7 @@ int socket_listen(int sock, int backlog)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int socket_set_reuseaddr(int sock, int reuseP)
|
int _socket_set_reuseaddr(struct __sourceloc __whence, int sock, int reuseP)
|
||||||
{
|
{
|
||||||
if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &reuseP, sizeof reuseP) == -1) {
|
if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &reuseP, sizeof reuseP) == -1) {
|
||||||
WARNF_perror("setsockopt(%d,SOL_SOCKET,SO_REUSEADDR,&%d,%u)", sock, reuseP, (unsigned)sizeof reuseP);
|
WARNF_perror("setsockopt(%d,SOL_SOCKET,SO_REUSEADDR,&%d,%u)", sock, reuseP, (unsigned)sizeof reuseP);
|
||||||
@ -103,7 +103,7 @@ int socket_set_reuseaddr(int sock, int reuseP)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int socket_set_rcvbufsize(int sock, unsigned buffer_size)
|
int _socket_set_rcvbufsize(struct __sourceloc __whence, int sock, unsigned buffer_size)
|
||||||
{
|
{
|
||||||
if (setsockopt(sock, SOL_SOCKET, SO_RCVBUF, &buffer_size, sizeof buffer_size) == -1) {
|
if (setsockopt(sock, SOL_SOCKET, SO_RCVBUF, &buffer_size, sizeof buffer_size) == -1) {
|
||||||
WARNF_perror("setsockopt(%d,SOL_SOCKET,SO_RCVBUF,&%u,%u)", sock, buffer_size, (unsigned)sizeof buffer_size);
|
WARNF_perror("setsockopt(%d,SOL_SOCKET,SO_RCVBUF,&%u,%u)", sock, buffer_size, (unsigned)sizeof buffer_size);
|
||||||
|
Loading…
Reference in New Issue
Block a user