summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGarrett D'Amore <garrett@damore.org>2019-12-25 11:01:25 -0800
committerGarrett D'Amore <garrett@damore.org>2019-12-26 15:45:48 -0800
commitd590eceab74772a8d5fa50c94074b09927577ee4 (patch)
tree8c34dc1f510d86540e27437ee15f80e9d88306bb /src
parent440ddf86b3b3b6be47943c5b6408d63b091f2c28 (diff)
downloadnng-d590eceab74772a8d5fa50c94074b09927577ee4.tar.gz
nng-d590eceab74772a8d5fa50c94074b09927577ee4.tar.bz2
nng-d590eceab74772a8d5fa50c94074b09927577ee4.zip
Various clang tidy fixups in the POSIX pollers.
Diffstat (limited to 'src')
-rw-r--r--src/platform/posix/posix_ipcconn.c20
-rw-r--r--src/platform/posix/posix_ipcdial.c14
-rw-r--r--src/platform/posix/posix_ipclisten.c6
-rw-r--r--src/platform/posix/posix_pollq.h15
-rw-r--r--src/platform/posix/posix_pollq_epoll.c24
-rw-r--r--src/platform/posix/posix_pollq_kqueue.c8
-rw-r--r--src/platform/posix/posix_pollq_poll.c8
-rw-r--r--src/platform/posix/posix_pollq_port.c10
-rw-r--r--src/platform/posix/posix_tcpconn.c17
-rw-r--r--src/platform/posix/posix_tcpdial.c22
-rw-r--r--src/platform/posix/posix_tcplisten.c6
-rw-r--r--src/platform/posix/posix_udp.c21
12 files changed, 77 insertions, 94 deletions
diff --git a/src/platform/posix/posix_ipcconn.c b/src/platform/posix/posix_ipcconn.c
index d3b997a9..f703b583 100644
--- a/src/platform/posix/posix_ipcconn.c
+++ b/src/platform/posix/posix_ipcconn.c
@@ -15,19 +15,19 @@
#include <fcntl.h>
#include <poll.h>
#include <stdbool.h>
-#include <stdio.h>
-#include <stdlib.h>
#include <string.h>
#include <sys/socket.h>
-#include <sys/types.h>
#include <sys/uio.h>
#include <sys/un.h>
-#include <unistd.h>
#if defined(NNG_HAVE_GETPEERUCRED)
#include <ucred.h>
#elif defined(NNG_HAVE_LOCALPEERCRED) || defined(NNG_HAVE_SOCKPEERCRED)
#include <sys/ucred.h>
#endif
+#if defined(NNG_HAVE_GETPEEREID)
+#include <sys/types.h>
+#include <unistd.h>
+#endif
#ifndef MSG_NOSIGNAL
#define MSG_NOSIGNAL 0
@@ -206,27 +206,27 @@ ipc_close(void *arg)
}
static void
-ipc_cb(nni_posix_pfd *pfd, int events, void *arg)
+ipc_cb(nni_posix_pfd *pfd, unsigned events, void *arg)
{
ipc_conn *c = arg;
- if (events & (POLLHUP | POLLERR | POLLNVAL)) {
+ if (events & (NNI_POLL_HUP | NNI_POLL_ERR | NNI_POLL_INVAL)) {
ipc_error(c, NNG_ECONNSHUT);
return;
}
nni_mtx_lock(&c->mtx);
- if (events & POLLIN) {
+ if ((events & NNI_POLL_IN) != 0) {
ipc_doread(c);
}
- if (events & POLLOUT) {
+ if ((events & NNI_POLL_OUT) != 0) {
ipc_dowrite(c);
}
events = 0;
if (!nni_list_empty(&c->writeq)) {
- events |= POLLOUT;
+ events |= NNI_POLL_OUT;
}
if (!nni_list_empty(&c->readq)) {
- events |= POLLIN;
+ events |= NNI_POLL_IN;
}
if ((!c->closed) && (events != 0)) {
nni_posix_pfd_arm(pfd, events);
diff --git a/src/platform/posix/posix_ipcdial.c b/src/platform/posix/posix_ipcdial.c
index 3182b390..3ce8c401 100644
--- a/src/platform/posix/posix_ipcdial.c
+++ b/src/platform/posix/posix_ipcdial.c
@@ -11,16 +11,10 @@
#include "core/nng_impl.h"
-#include <arpa/inet.h>
#include <errno.h>
-#include <fcntl.h>
#include <netinet/in.h>
-#include <stdio.h>
-#include <stdlib.h>
#include <string.h>
#include <sys/socket.h>
-#include <sys/types.h>
-#include <sys/uio.h>
#include <unistd.h>
#ifndef SOCK_CLOEXEC
@@ -86,7 +80,7 @@ ipc_dialer_cancel(nni_aio *aio, void *arg, int rv)
}
static void
-ipc_dialer_cb(nni_posix_pfd *pfd, int ev, void *arg)
+ipc_dialer_cb(nni_posix_pfd *pfd, unsigned ev, void *arg)
{
nni_ipc_conn * c = arg;
nni_ipc_dialer *d = c->dialer;
@@ -100,7 +94,7 @@ ipc_dialer_cb(nni_posix_pfd *pfd, int ev, void *arg)
return;
}
- if (ev & POLLNVAL) {
+ if ((ev & NNI_POLL_INVAL) != 0) {
rv = EBADF;
} else {
@@ -187,7 +181,7 @@ ipc_dialer_dial(void *arg, nni_aio *aio)
if ((rv = nni_aio_schedule(aio, ipc_dialer_cancel, d)) != 0) {
goto error;
}
- if ((rv = connect(fd, (void *) &ss, sslen)) != 0) {
+ if (connect(fd, (void *) &ss, sslen) != 0) {
if (errno != EINPROGRESS) {
if (errno == ENOENT) {
// No socket present means nobody listening.
@@ -198,7 +192,7 @@ ipc_dialer_dial(void *arg, nni_aio *aio)
goto error;
}
// Asynchronous connect.
- if ((rv = nni_posix_pfd_arm(pfd, POLLOUT)) != 0) {
+ if ((rv = nni_posix_pfd_arm(pfd, NNI_POLL_OUT)) != 0) {
goto error;
}
c->dial_aio = aio;
diff --git a/src/platform/posix/posix_ipclisten.c b/src/platform/posix/posix_ipclisten.c
index 2b5d0edd..da3eab7b 100644
--- a/src/platform/posix/posix_ipclisten.c
+++ b/src/platform/posix/posix_ipclisten.c
@@ -102,7 +102,7 @@ ipc_listener_doaccept(ipc_listener *l)
case EWOULDBLOCK:
#endif
#endif
- rv = nni_posix_pfd_arm(l->pfd, POLLIN);
+ rv = nni_posix_pfd_arm(l->pfd, NNI_POLL_IN);
if (rv != 0) {
nni_aio_list_remove(aio);
nni_aio_finish_error(aio, rv);
@@ -146,13 +146,13 @@ ipc_listener_doaccept(ipc_listener *l)
}
static void
-ipc_listener_cb(nni_posix_pfd *pfd, int events, void *arg)
+ipc_listener_cb(nni_posix_pfd *pfd, unsigned events, void *arg)
{
ipc_listener *l = arg;
NNI_ARG_UNUSED(pfd);
nni_mtx_lock(&l->mtx);
- if (events & POLLNVAL) {
+ if ((events & NNI_POLL_INVAL) != 0) {
ipc_listener_doclose(l);
nni_mtx_unlock(&l->mtx);
return;
diff --git a/src/platform/posix/posix_pollq.h b/src/platform/posix/posix_pollq.h
index b9786330..76105acc 100644
--- a/src/platform/posix/posix_pollq.h
+++ b/src/platform/posix/posix_pollq.h
@@ -1,5 +1,5 @@
//
-// Copyright 2018 Staysail Systems, Inc. <info@staysail.tech>
+// Copyright 2019 Staysail Systems, Inc. <info@staysail.tech>
// Copyright 2018 Capitar IT Group BV <info@capitar.com>
//
// This software is supplied under the terms of the MIT License, a
@@ -23,18 +23,21 @@
#include <poll.h>
typedef struct nni_posix_pfd nni_posix_pfd;
-typedef void (*nni_posix_pfd_cb)(nni_posix_pfd *, int, void *);
-
-extern int nni_posix_pollq_sysinit(void);
-extern void nni_posix_pollq_sysfini(void);
+typedef void (*nni_posix_pfd_cb)(nni_posix_pfd *, unsigned, void *);
extern int nni_posix_pfd_init(nni_posix_pfd **, int);
extern void nni_posix_pfd_fini(nni_posix_pfd *);
-extern int nni_posix_pfd_arm(nni_posix_pfd *, int);
+extern int nni_posix_pfd_arm(nni_posix_pfd *, unsigned);
extern int nni_posix_pfd_fd(nni_posix_pfd *);
extern void nni_posix_pfd_close(nni_posix_pfd *);
extern void nni_posix_pfd_set_cb(nni_posix_pfd *, nni_posix_pfd_cb, void *);
+#define NNI_POLL_IN ((unsigned) POLLIN)
+#define NNI_POLL_OUT ((unsigned) POLLOUT)
+#define NNI_POLL_HUP ((unsigned) POLLHUP)
+#define NNI_POLL_ERR ((unsigned) POLLERR)
+#define NNI_POLL_INVAL ((unsigned) POLLNVAL)
+
#endif // NNG_PLATFORM_POSIX
#endif // PLATFORM_POSIX_POLLQ_H
diff --git a/src/platform/posix/posix_pollq_epoll.c b/src/platform/posix/posix_pollq_epoll.c
index 8af4f253..8ec3bc3f 100644
--- a/src/platform/posix/posix_pollq_epoll.c
+++ b/src/platform/posix/posix_pollq_epoll.c
@@ -35,7 +35,7 @@ typedef struct nni_posix_pollq nni_posix_pollq;
#define NNI_MAX_EPOLL_EVENTS 64
// flags we always want enabled as long as at least one event is active
-#define NNI_EPOLL_FLAGS (EPOLLONESHOT | EPOLLERR)
+#define NNI_EPOLL_FLAGS ((unsigned) EPOLLONESHOT | (unsigned) EPOLLERR)
// Locking strategy:
//
@@ -69,7 +69,7 @@ struct nni_posix_pfd {
bool closed;
bool closing;
bool reap;
- int events;
+ unsigned events;
nni_mtx mtx;
nni_cv cv;
};
@@ -112,7 +112,7 @@ nni_posix_pfd_init(nni_posix_pfd **pfdp, int fd)
ev.events = 0;
ev.data.ptr = pfd;
- if ((rv = epoll_ctl(pq->epfd, EPOLL_CTL_ADD, fd, &ev)) != 0) {
+ if (epoll_ctl(pq->epfd, EPOLL_CTL_ADD, fd, &ev) != 0) {
rv = nni_plat_errno(errno);
nni_cv_fini(&pfd->cv);
NNI_FREE_STRUCT(pfd);
@@ -124,7 +124,7 @@ nni_posix_pfd_init(nni_posix_pfd **pfdp, int fd)
}
int
-nni_posix_pfd_arm(nni_posix_pfd *pfd, int events)
+nni_posix_pfd_arm(nni_posix_pfd *pfd, unsigned events)
{
nni_posix_pollq *pq = pfd->pq;
@@ -260,7 +260,8 @@ nni_posix_poll_thr(void *arg)
ev = &events[i];
// If the waker pipe was signaled, read from it.
- if ((ev->data.ptr == NULL) && (ev->events & POLLIN)) {
+ if ((ev->data.ptr == NULL) &&
+ (ev->events & (unsigned) POLLIN)) {
uint64_t clear;
(void) read(pq->evfd, &clear, sizeof(clear));
reap = true;
@@ -268,20 +269,21 @@ nni_posix_poll_thr(void *arg)
nni_posix_pfd * pfd = ev->data.ptr;
nni_posix_pfd_cb cb;
void * cbarg;
- int events;
+ unsigned mask;
- events = ev->events &
- (EPOLLIN | EPOLLOUT | EPOLLERR);
+ mask = ev->events &
+ ((unsigned) EPOLLIN | (unsigned) EPOLLOUT |
+ (unsigned) EPOLLERR);
nni_mtx_lock(&pfd->mtx);
- pfd->events &= ~events;
- cb = pfd->cb;
+ pfd->events &= ~mask;
+ cb = pfd->cb;
cbarg = pfd->arg;
nni_mtx_unlock(&pfd->mtx);
// Execute the callback with lock released
if (cb != NULL) {
- cb(pfd, events, cbarg);
+ cb(pfd, mask, cbarg);
}
}
}
diff --git a/src/platform/posix/posix_pollq_kqueue.c b/src/platform/posix/posix_pollq_kqueue.c
index 1aef2a93..72d306c7 100644
--- a/src/platform/posix/posix_pollq_kqueue.c
+++ b/src/platform/posix/posix_pollq_kqueue.c
@@ -1,5 +1,5 @@
//
-// Copyright 2018 Staysail Systems, Inc. <info@staysail.tech>
+// Copyright 2019 Staysail Systems, Inc. <info@staysail.tech>
// Copyright 2018 Capitar IT Group BV <info@capitar.com>
// Copyright 2018 Liam Staskawicz <liam@stask.net>
//
@@ -42,7 +42,7 @@ struct nni_posix_pfd {
nni_posix_pfd_cb cb; // user callback on event
nni_cv cv; // signaled when poller has unregistered
nni_mtx mtx;
- int events;
+ unsigned events;
bool closing;
bool closed;
};
@@ -164,7 +164,7 @@ nni_posix_pfd_set_cb(nni_posix_pfd *pf, nni_posix_pfd_cb cb, void *arg)
}
int
-nni_posix_pfd_arm(nni_posix_pfd *pf, int events)
+nni_posix_pfd_arm(nni_posix_pfd *pf, unsigned events)
{
struct kevent ev[2];
int nev = 0;
@@ -224,7 +224,7 @@ nni_posix_poll_thr(void *arg)
nni_posix_pfd * pf;
nni_posix_pfd_cb cb;
void * cbarg;
- int revents;
+ unsigned revents;
bool reap = false;
n = kevent(pq->kq, NULL, 0, evs, NNI_MAX_KQUEUE_EVENTS, NULL);
diff --git a/src/platform/posix/posix_pollq_poll.c b/src/platform/posix/posix_pollq_poll.c
index ec487de5..12c5e541 100644
--- a/src/platform/posix/posix_pollq_poll.c
+++ b/src/platform/posix/posix_pollq_poll.c
@@ -1,5 +1,5 @@
//
-// Copyright 2018 Staysail Systems, Inc. <info@staysail.tech>
+// Copyright 2019 Staysail Systems, Inc. <info@staysail.tech>
// Copyright 2018 Capitar IT Group BV <info@capitar.com>
//
// This software is supplied under the terms of the MIT License, a
@@ -61,7 +61,7 @@ struct nni_posix_pfd {
nni_list_node node;
nni_cv cv;
nni_mtx mtx;
- int events;
+ unsigned events;
nni_posix_pfd_cb cb;
void * arg;
};
@@ -164,7 +164,7 @@ nni_posix_pfd_fini(nni_posix_pfd *pfd)
}
int
-nni_posix_pfd_arm(nni_posix_pfd *pfd, int events)
+nni_posix_pfd_arm(nni_posix_pfd *pfd, unsigned events)
{
nni_posix_pollq *pq = pfd->pq;
@@ -191,7 +191,7 @@ nni_posix_poll_thr(void *arg)
for (;;) {
int nfds;
- int events;
+ unsigned events;
nni_posix_pfd *pfd;
nni_mtx_lock(&pq->mtx);
diff --git a/src/platform/posix/posix_pollq_port.c b/src/platform/posix/posix_pollq_port.c
index 63c1d1d1..0a1110bf 100644
--- a/src/platform/posix/posix_pollq_port.c
+++ b/src/platform/posix/posix_pollq_port.c
@@ -1,5 +1,5 @@
//
-// Copyright 2018 Staysail Systems, Inc. <info@staysail.tech>
+// Copyright 2019 Staysail Systems, Inc. <info@staysail.tech>
// Copyright 2018 Capitar IT Group BV <info@capitar.com>
//
// This software is supplied under the terms of the MIT License, a
@@ -38,7 +38,7 @@ struct nni_posix_pfd {
int fd;
nni_mtx mtx;
nni_cv cv;
- int events;
+ unsigned events;
bool closed;
bool closing;
nni_posix_pfd_cb cb;
@@ -130,7 +130,7 @@ nni_posix_pfd_fini(nni_posix_pfd *pfd)
}
int
-nni_posix_pfd_arm(nni_posix_pfd *pfd, int events)
+nni_posix_pfd_arm(nni_posix_pfd *pfd, unsigned events)
{
nni_posix_pollq *pq = pfd->pq;
@@ -138,7 +138,7 @@ nni_posix_pfd_arm(nni_posix_pfd *pfd, int events)
if (!pfd->closing) {
pfd->events |= events;
if (port_associate(pq->port, PORT_SOURCE_FD, pfd->fd,
- pfd->events, pfd) != 0) {
+ (int) pfd->events, pfd) != 0) {
int rv = nni_plat_errno(errno);
nni_mtx_unlock(&pfd->mtx);
return (rv);
@@ -155,7 +155,7 @@ nni_posix_poll_thr(void *arg)
nni_posix_pollq *pq = arg;
port_event_t ev[NNI_MAX_PORTEV];
nni_posix_pfd * pfd;
- int events;
+ unsigned events;
nni_posix_pfd_cb cb;
void * arg;
unsigned n;
diff --git a/src/platform/posix/posix_tcpconn.c b/src/platform/posix/posix_tcpconn.c
index fc867ce0..d4ffbf21 100644
--- a/src/platform/posix/posix_tcpconn.c
+++ b/src/platform/posix/posix_tcpconn.c
@@ -11,20 +11,15 @@
#include "core/nng_impl.h"
-#include <arpa/inet.h>
#include <errno.h>
#include <fcntl.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
#include <poll.h>
#include <stdbool.h>
-#include <stdio.h>
-#include <stdlib.h>
#include <string.h>
#include <sys/socket.h>
-#include <sys/types.h>
#include <sys/uio.h>
-#include <unistd.h>
#ifndef MSG_NOSIGNAL
#define MSG_NOSIGNAL 0
@@ -224,27 +219,27 @@ tcp_free(void *arg)
}
static void
-tcp_cb(nni_posix_pfd *pfd, int events, void *arg)
+tcp_cb(nni_posix_pfd *pfd, unsigned events, void *arg)
{
nni_tcp_conn *c = arg;
- if (events & (POLLHUP | POLLERR | POLLNVAL)) {
+ if (events & (NNI_POLL_HUP | NNI_POLL_ERR | NNI_POLL_INVAL)) {
tcp_error(c, NNG_ECONNSHUT);
return;
}
nni_mtx_lock(&c->mtx);
- if (events & POLLIN) {
+ if ((events & NNI_POLL_IN) != 0) {
tcp_doread(c);
}
- if (events & POLLOUT) {
+ if ((events & NNI_POLL_OUT) != 0) {
tcp_dowrite(c);
}
events = 0;
if (!nni_list_empty(&c->writeq)) {
- events |= POLLOUT;
+ events |= NNI_POLL_OUT;
}
if (!nni_list_empty(&c->readq)) {
- events |= POLLIN;
+ events |= NNI_POLL_IN;
}
if ((!c->closed) && (events != 0)) {
nni_posix_pfd_arm(pfd, events);
diff --git a/src/platform/posix/posix_tcpdial.c b/src/platform/posix/posix_tcpdial.c
index 21ad862d..457a64ea 100644
--- a/src/platform/posix/posix_tcpdial.c
+++ b/src/platform/posix/posix_tcpdial.c
@@ -1,5 +1,5 @@
//
-// Copyright 2018 Staysail Systems, Inc. <info@staysail.tech>
+// Copyright 2019 Staysail Systems, Inc. <info@staysail.tech>
// Copyright 2018 Capitar IT Group BV <info@capitar.com>
// Copyright 2018 Devolutions <info@devolutions.net>
//
@@ -11,16 +11,10 @@
#include "core/nng_impl.h"
-#include <arpa/inet.h>
#include <errno.h>
-#include <fcntl.h>
#include <netinet/in.h>
-#include <stdio.h>
-#include <stdlib.h>
#include <string.h>
#include <sys/socket.h>
-#include <sys/types.h>
-#include <sys/uio.h>
#include <unistd.h>
#ifndef SOCK_CLOEXEC
@@ -107,7 +101,7 @@ tcp_dialer_cancel(nni_aio *aio, void *arg, int rv)
}
static void
-tcp_dialer_cb(nni_posix_pfd *pfd, int ev, void *arg)
+tcp_dialer_cb(nni_posix_pfd *pfd, unsigned ev, void *arg)
{
nni_tcp_conn * c = arg;
nni_tcp_dialer *d = c->dialer;
@@ -123,7 +117,7 @@ tcp_dialer_cb(nni_posix_pfd *pfd, int ev, void *arg)
return;
}
- if (ev & POLLNVAL) {
+ if ((ev & NNI_POLL_INVAL) != 0) {
rv = EBADF;
} else {
@@ -193,8 +187,8 @@ nni_tcp_dial(nni_tcp_dialer *d, nni_aio *aio)
return;
}
- // This arranges for the fd to be in nonblocking mode, and adds the
- // pollfd to the list.
+ // This arranges for the fd to be in non-blocking mode, and adds the
+ // poll fd to the list.
if ((rv = nni_posix_pfd_init(&pfd, fd)) != 0) {
(void) close(fd);
nni_aio_finish_error(aio, rv);
@@ -214,7 +208,7 @@ nni_tcp_dial(nni_tcp_dialer *d, nni_aio *aio)
goto error;
}
if (d->srclen != 0) {
- if ((rv = bind(fd, (void *) &d->src, d->srclen)) != 0) {
+ if (bind(fd, (void *) &d->src, d->srclen) != 0) {
rv = nni_plat_errno(errno);
goto error;
}
@@ -222,13 +216,13 @@ nni_tcp_dial(nni_tcp_dialer *d, nni_aio *aio)
if ((rv = nni_aio_schedule(aio, tcp_dialer_cancel, d)) != 0) {
goto error;
}
- if ((rv = connect(fd, (void *) &ss, sslen)) != 0) {
+ if (connect(fd, (void *) &ss, sslen) != 0) {
if (errno != EINPROGRESS) {
rv = nni_plat_errno(errno);
goto error;
}
// Asynchronous connect.
- if ((rv = nni_posix_pfd_arm(pfd, POLLOUT)) != 0) {
+ if ((rv = nni_posix_pfd_arm(pfd, NNI_POLL_OUT)) != 0) {
goto error;
}
c->dial_aio = aio;
diff --git a/src/platform/posix/posix_tcplisten.c b/src/platform/posix/posix_tcplisten.c
index 1edeccbc..10867453 100644
--- a/src/platform/posix/posix_tcplisten.c
+++ b/src/platform/posix/posix_tcplisten.c
@@ -114,7 +114,7 @@ tcp_listener_doaccept(nni_tcp_listener *l)
case EWOULDBLOCK:
#endif
#endif
- rv = nni_posix_pfd_arm(l->pfd, POLLIN);
+ rv = nni_posix_pfd_arm(l->pfd, NNI_POLL_IN);
if (rv != 0) {
nni_aio_list_remove(aio);
nni_aio_finish_error(aio, rv);
@@ -160,13 +160,13 @@ tcp_listener_doaccept(nni_tcp_listener *l)
}
static void
-tcp_listener_cb(nni_posix_pfd *pfd, int events, void *arg)
+tcp_listener_cb(nni_posix_pfd *pfd, unsigned events, void *arg)
{
nni_tcp_listener *l = arg;
NNI_ARG_UNUSED(pfd);
nni_mtx_lock(&l->mtx);
- if (events & POLLNVAL) {
+ if ((events & NNI_POLL_INVAL) != 0) {
tcp_listener_doclose(l);
nni_mtx_unlock(&l->mtx);
return;
diff --git a/src/platform/posix/posix_udp.c b/src/platform/posix/posix_udp.c
index 015fb4ad..b8939d68 100644
--- a/src/platform/posix/posix_udp.c
+++ b/src/platform/posix/posix_udp.c
@@ -16,12 +16,8 @@
#include <errno.h>
#include <fcntl.h>
#include <netinet/in.h>
-#include <stdio.h>
-#include <stdlib.h>
#include <string.h>
#include <sys/socket.h>
-#include <sys/types.h>
-#include <sys/uio.h>
#include <unistd.h>
// UDP support.
@@ -158,27 +154,28 @@ nni_posix_udp_dosend(nni_plat_udp *udp)
// This function is called by the poller on activity on the FD.
static void
-nni_posix_udp_cb(nni_posix_pfd *pfd, int events, void *arg)
+nni_posix_udp_cb(nni_posix_pfd *pfd, unsigned events, void *arg)
{
nni_plat_udp *udp = arg;
NNI_ARG_UNUSED(pfd);
nni_mtx_lock(&udp->udp_mtx);
- if (events & POLLIN) {
+ if (events & (unsigned) POLLIN) {
nni_posix_udp_dorecv(udp);
}
- if (events & POLLOUT) {
+ if (events & (unsigned) POLLOUT) {
nni_posix_udp_dosend(udp);
}
- if (events & (POLLHUP | POLLERR | POLLNVAL)) {
+ if (events &
+ ((unsigned) POLLHUP | (unsigned) POLLERR | (unsigned) POLLNVAL)) {
nni_posix_udp_doclose(udp);
} else {
events = 0;
if (!nni_list_empty(&udp->udp_sendq)) {
- events |= POLLOUT;
+ events |= (unsigned) POLLOUT;
}
if (!nni_list_empty(&udp->udp_recvq)) {
- events |= POLLIN;
+ events |= (unsigned) POLLIN;
}
if (events) {
int rv;
@@ -317,11 +314,9 @@ nni_plat_udp_sockname(nni_plat_udp *udp, nni_sockaddr *sa)
{
struct sockaddr_storage ss;
socklen_t sz;
- int rv;
sz = sizeof(ss);
- if ((rv = getsockname(udp->udp_fd, (struct sockaddr *) &ss, &sz)) <
- 0) {
+ if (getsockname(udp->udp_fd, (struct sockaddr *) &ss, &sz) < 0) {
return (nni_plat_errno(errno));
}
return (nni_posix_sockaddr2nn(sa, &ss));