Skip to content

Commit

Permalink
net/types: move socket helpers and rename RE_ERRNO_SOCK and RE_BAD_SO…
Browse files Browse the repository at this point in the history
…CK (#608)
  • Loading branch information
sreimers authored Dec 6, 2022
1 parent c6e5203 commit a438768
Show file tree
Hide file tree
Showing 7 changed files with 96 additions and 95 deletions.
11 changes: 0 additions & 11 deletions include/re_net.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,6 @@
#include <arpa/inet.h>
#endif

/* Socket helpers */
#ifdef WIN32
#define ERRNO_SOCK WSAGetLastError()
#define BAD_SOCK INVALID_SOCKET
typedef size_t re_sock_t;
#else
#define ERRNO_SOCK errno
#define BAD_SOCK -1
typedef int re_sock_t;
#endif

/** Length of IPv4 address string */
#ifndef INET_ADDRSTRLEN
#define INET_ADDRSTRLEN 16
Expand Down
11 changes: 11 additions & 0 deletions include/re_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -258,3 +258,14 @@ typedef SSIZE_T ssize_t;
#else
#define re_restrict restrict
#endif

/* Socket helpers */
#ifdef WIN32
#define RE_ERRNO_SOCK WSAGetLastError()
#define RE_BAD_SOCK INVALID_SOCKET
typedef size_t re_sock_t;
#else
#define RE_ERRNO_SOCK errno
#define RE_BAD_SOCK -1
typedef int re_sock_t;
#endif
4 changes: 2 additions & 2 deletions src/main/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -624,7 +624,7 @@ int fd_listen(re_sock_t fd, int flags, fd_h *fh, void *arg)
return err;
#endif

if (fd == BAD_SOCK) {
if (fd == RE_BAD_SOCK) {
DEBUG_WARNING("fd_listen: corrupt fd %d\n", fd);
return EBADF;
}
Expand Down Expand Up @@ -806,7 +806,7 @@ static int fd_poll(struct re *re)
}

if (n < 0)
return ERRNO_SOCK;
return RE_ERRNO_SOCK;

/* Check for events */
for (i=0; (n > 0) && (i < re->nfds); i++) {
Expand Down
8 changes: 4 additions & 4 deletions src/mqueue/mqueue.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@ static void destructor(void *arg)
{
struct mqueue *q = arg;

if (q->pfd[0] != BAD_SOCK) {
if (q->pfd[0] != RE_BAD_SOCK) {
fd_close(q->pfd[0]);
(void)close(q->pfd[0]);
}
if (q->pfd[1] != BAD_SOCK)
if (q->pfd[1] != RE_BAD_SOCK)
(void)close(q->pfd[1]);
}

Expand Down Expand Up @@ -111,9 +111,9 @@ int mqueue_alloc(struct mqueue **mqp, mqueue_h *h, void *arg)
mq->h = h;
mq->arg = arg;

mq->pfd[0] = mq->pfd[1] = BAD_SOCK;
mq->pfd[0] = mq->pfd[1] = RE_BAD_SOCK;
if (pipe(mq->pfd) < 0) {
err = ERRNO_SOCK;
err = RE_ERRNO_SOCK;
goto out;
}

Expand Down
2 changes: 1 addition & 1 deletion src/sa/sa.c
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ int sa_ntop(const struct sa *sa, char *buf, int size)
}

if (!ret)
return ERRNO_SOCK;
return RE_ERRNO_SOCK;

return 0;
}
Expand Down
Loading

0 comments on commit a438768

Please sign in to comment.