qpid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From acon...@apache.org
Subject qpid-proton git commit: PROTON-1460: implement pn_netaddr functions for epoll proactor
Date Mon, 01 May 2017 21:10:51 GMT
Repository: qpid-proton
Updated Branches:
  refs/heads/master 6995cfd63 -> 2c6c57e29


PROTON-1460: implement pn_netaddr functions for epoll proactor

Also made netaddr.h const-correct and updated both libuv and epoll implementations.


Project: http://git-wip-us.apache.org/repos/asf/qpid-proton/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-proton/commit/2c6c57e2
Tree: http://git-wip-us.apache.org/repos/asf/qpid-proton/tree/2c6c57e2
Diff: http://git-wip-us.apache.org/repos/asf/qpid-proton/diff/2c6c57e2

Branch: refs/heads/master
Commit: 2c6c57e290fd1f10278f98befabf5558b240d305
Parents: 6995cfd
Author: Alan Conway <aconway@redhat.com>
Authored: Mon May 1 16:45:00 2017 -0400
Committer: Alan Conway <aconway@redhat.com>
Committed: Mon May 1 17:02:09 2017 -0400

----------------------------------------------------------------------
 proton-c/include/proton/netaddr.h | 10 +++++-----
 proton-c/src/proactor/epoll.c     | 35 +++++++++++++++++++++++-----------
 proton-c/src/proactor/libuv.c     | 12 ++++++------
 proton-c/src/tests/proactor.c     |  4 ++--
 4 files changed, 37 insertions(+), 24 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/2c6c57e2/proton-c/include/proton/netaddr.h
----------------------------------------------------------------------
diff --git a/proton-c/include/proton/netaddr.h b/proton-c/include/proton/netaddr.h
index 21b79ff..9cde766 100644
--- a/proton-c/include/proton/netaddr.h
+++ b/proton-c/include/proton/netaddr.h
@@ -43,17 +43,17 @@ typedef struct pn_netaddr_t pn_netaddr_t;
  * @return the length of the string (excluding trailing '\0'), if >= size then
  * the address was truncated.
  */
-PNP_EXTERN int pn_netaddr_str(pn_netaddr_t *addr, char *buf, size_t size);
+PNP_EXTERN int pn_netaddr_str(const pn_netaddr_t *addr, char *buf, size_t size);
 
 /**
  * Get the local address of a transport. Return NULL if not available.
  */
-PNP_EXTERN pn_netaddr_t *pn_netaddr_local(pn_transport_t *t);
+PNP_EXTERN const pn_netaddr_t *pn_netaddr_local(pn_transport_t *t);
 
 /**
  * Get the remote address of a transport. Return NULL if not available.
  */
-PNP_EXTERN pn_netaddr_t *pn_netaddr_remote(pn_transport_t *t);
+PNP_EXTERN const pn_netaddr_t *pn_netaddr_remote(pn_transport_t *t);
 
 struct sockaddr;
 
@@ -61,13 +61,13 @@ struct sockaddr;
  * On POSIX or Windows, get the underlying `struct sockaddr`.
  * Return NULL if not available.
  */
-PNP_EXTERN struct sockaddr *pn_netaddr_sockaddr(pn_netaddr_t *na);
+PNP_EXTERN const struct sockaddr *pn_netaddr_sockaddr(const pn_netaddr_t *na);
 
 /**
  * On POSIX or Windows, get the size of the underlying `struct sockaddr`.
  * Return 0 if not available.
  */
-PNP_EXTERN size_t pn_netaddr_socklen(pn_netaddr_t *na);
+PNP_EXTERN size_t pn_netaddr_socklen(const pn_netaddr_t *na);
 
 /**
  * @}

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/2c6c57e2/proton-c/src/proactor/epoll.c
----------------------------------------------------------------------
diff --git a/proton-c/src/proactor/epoll.c b/proton-c/src/proactor/epoll.c
index 6ea61c7..36d7263 100644
--- a/proton-c/src/proactor/epoll.c
+++ b/proton-c/src/proactor/epoll.c
@@ -425,6 +425,10 @@ static void psocket_init(psocket_t* ps, pn_proactor_t* p, bool is_conn,
const ch
   strncpy(ps->port, port, sizeof(ps->port));
 }
 
+struct pn_netaddr_t {
+  struct sockaddr_storage ss;
+};
+
 typedef struct pconnection_t {
   psocket_t psocket;
   pcontext_t context;
@@ -445,6 +449,7 @@ typedef struct pconnection_t {
   pn_event_t *cached_event;
   pn_event_batch_t batch;
   pn_connection_driver_t driver;
+  struct pn_netaddr_t local, remote; /* Actual addresses */
 } pconnection_t;
 
 struct pn_listener_t {
@@ -967,6 +972,13 @@ void pconnection_start(pconnection_t *pc) {
   int efd = pc->psocket.proactor->epollfd;
   start_polling(&pc->timer.epoll_io, efd);  // TODO: check for error
 
+  int fd = pc->psocket.sockfd;
+  socklen_t len = sizeof(pc->local);
+  getsockname(fd, (struct sockaddr*)&pc->local, &len);
+  len = sizeof(pc->remote);
+  getpeername(fd, (struct sockaddr*)&pc->remote, &len);
+
+  start_polling(&pc->timer.epoll_io, efd);  // TODO: check for error
   pc->read_closed = false;
   pc->write_closed = false;
   epoll_extended_t *ee = &pc->psocket.epoll_io;
@@ -1724,27 +1736,28 @@ void pn_proactor_disconnect(pn_proactor_t *p, pn_condition_t *cond)
{
     wake_notify(&p->context);
 }
 
-struct sockaddr *pn_netaddr_sockaddr(pn_netaddr_t *addr) {
-  return NULL;
+const struct sockaddr *pn_netaddr_sockaddr(const pn_netaddr_t *na) {
+  return (struct sockaddr*)na;
 }
 
-size_t pn_netaddr_socklen(pn_netaddr_t *addr) {
-  return 0;
+size_t pn_netaddr_socklen(const pn_netaddr_t *na) {
+  return sizeof(struct sockaddr_storage);
 }
 
-pn_netaddr_t *pn_netaddr_local(pn_transport_t *t) {
-  return NULL;
+const pn_netaddr_t *pn_netaddr_local(pn_transport_t *t) {
+  pconnection_t *pc = get_pconnection(pn_transport_connection(t));
+  return pc? &pc->local : NULL;
 }
 
-pn_netaddr_t *pn_netaddr_remote(pn_transport_t *t) {
-  return NULL;
+const pn_netaddr_t *pn_netaddr_remote(pn_transport_t *t) {
+  pconnection_t *pc = get_pconnection(pn_transport_connection(t));
+  return pc ? &pc->remote : NULL;
 }
 
-int pn_netaddr_str(pn_netaddr_t* addr, char *buf, size_t len) {
-  struct sockaddr_storage *sa = (struct sockaddr_storage*)addr;
+int pn_netaddr_str(const pn_netaddr_t* na, char *buf, size_t len) {
   char host[NI_MAXHOST];
   char port[NI_MAXSERV];
-  int err = getnameinfo((struct sockaddr *)sa, sizeof(*sa),
+  int err = getnameinfo((struct sockaddr *)&na->ss, sizeof(na->ss),
                         host, sizeof(host), port, sizeof(port),
                         NI_NUMERICHOST | NI_NUMERICSERV);
   if (!err) {

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/2c6c57e2/proton-c/src/proactor/libuv.c
----------------------------------------------------------------------
diff --git a/proton-c/src/proactor/libuv.c b/proton-c/src/proactor/libuv.c
index 22d0163..0a05424 100644
--- a/proton-c/src/proactor/libuv.c
+++ b/proton-c/src/proactor/libuv.c
@@ -1269,32 +1269,32 @@ void pn_listener_accept(pn_listener_t *l, pn_connection_t *c) {
   work_notify(&l->work);
 }
 
-struct sockaddr *pn_netaddr_sockaddr(pn_netaddr_t *na) {
+const struct sockaddr *pn_netaddr_sockaddr(const pn_netaddr_t *na) {
   return (struct sockaddr*)na;
 }
 
-size_t pn_netaddr_socklen(pn_netaddr_t *na) {
+size_t pn_netaddr_socklen(const pn_netaddr_t *na) {
   return sizeof(struct sockaddr_storage);
 }
 
-pn_netaddr_t *pn_netaddr_local(pn_transport_t *t) {
+const pn_netaddr_t *pn_netaddr_local(pn_transport_t *t) {
   pconnection_t *pc = get_pconnection(pn_transport_connection(t));
   return pc? &pc->local : NULL;
 }
 
-pn_netaddr_t *pn_netaddr_remote(pn_transport_t *t) {
+const pn_netaddr_t *pn_netaddr_remote(pn_transport_t *t) {
   pconnection_t *pc = get_pconnection(pn_transport_connection(t));
   return pc ? &pc->remote : NULL;
 }
 
-int pn_netaddr_str(struct pn_netaddr_t* na, char *buf, size_t len) {
+int pn_netaddr_str(const pn_netaddr_t* na, char *buf, size_t len) {
   char host[NI_MAXHOST];
   char port[NI_MAXSERV];
   int err = getnameinfo((struct sockaddr *)&na->ss, sizeof(na->ss),
                         host, sizeof(host), port, sizeof(port),
                         NI_NUMERICHOST | NI_NUMERICSERV);
   if (!err) {
-    return snprintf(buf, len, "%s:%s", host, port); /* FIXME aconway 2017-03-29: ipv6 format?
*/
+    return snprintf(buf, len, "%s:%s", host, port);
   } else {
     if (buf) *buf = '\0';
     return 0;

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/2c6c57e2/proton-c/src/tests/proactor.c
----------------------------------------------------------------------
diff --git a/proton-c/src/tests/proactor.c b/proton-c/src/tests/proactor.c
index 2839614..ba73033 100644
--- a/proton-c/src/tests/proactor.c
+++ b/proton-c/src/tests/proactor.c
@@ -758,8 +758,8 @@ static void test_netaddr(test_t *t) {
   TEST_STR_EQUAL(t, cl, sr);    /* client local == server remote */
 
   /* Examine as sockaddr */
-  pn_netaddr_t *na = pn_netaddr_remote(ct);
-  struct sockaddr *sa = pn_netaddr_sockaddr(na);
+  const pn_netaddr_t *na = pn_netaddr_remote(ct);
+  const struct sockaddr *sa = pn_netaddr_sockaddr(na);
   TEST_CHECK(t, AF_INET == sa->sa_family);
   char host[NI_MAXHOST] = "";
   char serv[NI_MAXSERV] = "";


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org


Mime
View raw message