You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@apr.apache.org by tr...@locus.apache.org on 2000/11/21 20:15:32 UTC

cvs commit: apr/test client.c server.c

trawick     00/11/21 11:15:30

  Modified:    test     client.c server.c
  Log:
  updates to changed interfaces to apr_set_port(), apr_get_port(),
  apr_set_ipaddr(), and apr_get_ipaddr()
  
  Revision  Changes    Path
  1.21      +10 -8     apr/test/client.c
  
  Index: client.c
  ===================================================================
  RCS file: /home/cvs/apr/test/client.c,v
  retrieving revision 1.20
  retrieving revision 1.21
  diff -u -r1.20 -r1.21
  --- client.c	2000/11/19 01:54:12	1.20
  +++ client.c	2000/11/21 19:15:27	1.21
  @@ -73,7 +73,7 @@
       char *dest = "127.0.0.1";
       apr_port_t local_port, remote_port;
       apr_interval_time_t read_timeout = -1;
  -    apr_sockaddr_t *destsa;
  +    apr_sockaddr_t *local_sa, *remote_sa;
   
       setbuf(stdout, NULL);
       if (argc > 1) {
  @@ -100,7 +100,7 @@
       fprintf(stdout, "OK\n");
   
       fprintf(stdout,"\tClient:  Making socket address...............");
  -    if ((stat = apr_getaddrinfo(&destsa, dest, APR_UNSPEC, 8021, 0, context)) 
  +    if ((stat = apr_getaddrinfo(&remote_sa, dest, APR_UNSPEC, 8021, 0, context)) 
           != APR_SUCCESS) {
           fprintf(stdout, "Failed!\n");
           fprintf(stdout, "Address resolution failed for %s: %s\n", 
  @@ -110,7 +110,7 @@
       fprintf(stdout,"OK\n");
   
       fprintf(stdout, "\tClient:  Creating new socket.......");
  -    if (apr_create_socket(&sock, destsa->sa.sin.sin_family, SOCK_STREAM,
  +    if (apr_create_socket(&sock, remote_sa->sa.sin.sin_family, SOCK_STREAM,
                             context) != APR_SUCCESS) {
           fprintf(stderr, "Couldn't create socket\n");
           exit(-1);
  @@ -119,7 +119,7 @@
   
       fprintf(stdout, "\tClient:  Connecting to socket.......");
   
  -    stat = apr_connect(sock, destsa);
  +    stat = apr_connect(sock, remote_sa);
   
       if (stat != APR_SUCCESS) {
           apr_close_socket(sock);
  @@ -140,10 +140,12 @@
           fprintf(stdout, "OK\n");
       }
   
  -    apr_get_ipaddr(&remote_ipaddr, APR_REMOTE, sock);
  -    apr_get_port(&remote_port, APR_REMOTE, sock);
  -    apr_get_ipaddr(&local_ipaddr, APR_LOCAL, sock);
  -    apr_get_port(&local_port, APR_LOCAL, sock);
  +    apr_get_sockaddr(&remote_sa, APR_REMOTE, sock);
  +    apr_get_ipaddr(&remote_ipaddr, remote_sa);
  +    apr_get_port(&remote_port, remote_sa);
  +    apr_get_sockaddr(&local_sa, APR_LOCAL, sock);
  +    apr_get_ipaddr(&local_ipaddr, local_sa);
  +    apr_get_port(&local_port, local_sa);
       fprintf(stdout, "\tClient socket: %s:%u -> %s:%u\n", local_ipaddr, local_port, remote_ipaddr, remote_port);
   
       fprintf(stdout, "\tClient:  Trying to send data over socket.......");
  
  
  
  1.21      +8 -6      apr/test/server.c
  
  Index: server.c
  ===================================================================
  RCS file: /home/cvs/apr/test/server.c,v
  retrieving revision 1.20
  retrieving revision 1.21
  diff -u -r1.20 -r1.21
  --- server.c	2000/11/19 14:24:18	1.20
  +++ server.c	2000/11/21 19:15:27	1.21
  @@ -73,7 +73,7 @@
       const char *bind_to_ipaddr = NULL;
       char *local_ipaddr, *remote_ipaddr;
       apr_port_t local_port, remote_port;
  -    apr_sockaddr_t *localsa = NULL;
  +    apr_sockaddr_t *localsa = NULL, *remotesa;
       apr_status_t stat;
       int family = APR_UNSPEC;
       char buf[128];
  @@ -155,8 +155,8 @@
       fprintf(stdout, "OK\n");
   
       if (!localsa) {
  -        apr_set_port(sock, APR_LOCAL, 8021);
           apr_get_sockaddr(&localsa, APR_LOCAL, sock);
  +        apr_set_port(localsa, 8021);
       }
   
       fprintf(stdout, "\tServer:  Binding socket to port.......");
  @@ -203,10 +203,12 @@
       }
       fprintf(stdout, "OK\n");
   
  -    apr_get_ipaddr(&remote_ipaddr, APR_REMOTE, sock2);
  -    apr_get_port(&remote_port, APR_REMOTE, sock2);
  -    apr_get_ipaddr(&local_ipaddr, APR_LOCAL, sock2);
  -    apr_get_port(&local_port, APR_LOCAL, sock2);
  +    apr_get_sockaddr(&remotesa, APR_REMOTE, sock2);
  +    apr_get_ipaddr(&remote_ipaddr, remotesa);
  +    apr_get_port(&remote_port, remotesa);
  +    apr_get_sockaddr(&localsa, APR_LOCAL, sock2);
  +    apr_get_ipaddr(&local_ipaddr, localsa);
  +    apr_get_port(&local_port, localsa);
       fprintf(stdout, "\tServer socket: %s:%u -> %s:%u\n", local_ipaddr, local_port, remote_ipaddr, remote_port);
   
       length = STRLEN;
  
  
  

Re: cvs commit: apr/test client.c server.c

Posted by Jeff Trawick <tr...@bellsouth.net>.
Greg Stein <gs...@lyra.org> writes:

> On Tue, Nov 21, 2000 at 07:15:32PM -0000, trawick@locus.apache.org wrote:
> > trawick     00/11/21 11:15:30
> > 
> >   Modified:    test     client.c server.c
> >   Log:
> >   updates to changed interfaces to apr_set_port(), apr_get_port(),
> >   apr_set_ipaddr(), and apr_get_ipaddr()
> >...
> >   --- server.c	2000/11/19 14:24:18	1.20
> >   +++ server.c	2000/11/21 19:15:27	1.21
> >   @@ -73,7 +73,7 @@
> >        const char *bind_to_ipaddr = NULL;
> >        char *local_ipaddr, *remote_ipaddr;
> >        apr_port_t local_port, remote_port;
> >   -    apr_sockaddr_t *localsa = NULL;
> >   +    apr_sockaddr_t *localsa = NULL, *remotesa;
> >        apr_status_t stat;
> >        int family = APR_UNSPEC;
> >        char buf[128];
> >   @@ -155,8 +155,8 @@
> >        fprintf(stdout, "OK\n");
> >    
> >        if (!localsa) {
> >   -        apr_set_port(sock, APR_LOCAL, 8021);
> >            apr_get_sockaddr(&localsa, APR_LOCAL, sock);
> >   +        apr_set_port(localsa, 8021);
> >        }
> 
> This seems a bit wonky. The above code implies that an apr_get_sockaddr()
> returns an address that is *attached* to the socket. That any changes to the
> address will reflect within the socket.

yep...

> That seems like it will introduce a number of subtle bugs.
> 
> - if people forget the attached state
> - what happens when it gets passed elsewhere
> - can it be used after the socket closes

no

> - etc

Well, the obvious alternative is to copy, but I'm not sure how many
copies of these things we'd end up with if apps aren't careful.

Perhaps a way to *copy* the sockaddr out of the socket could be
provided for apps that want to create an independent sockaddr which
looks like one of the sockaddrs associated with the socket but which
has an independent lifetime?

-- 
Jeff Trawick | trawick@ibm.net | PGP public key at web site:
     http://www.geocities.com/SiliconValley/Park/9289/
          Born in Roswell... married an alien...

Re: cvs commit: apr/test client.c server.c

Posted by Greg Stein <gs...@lyra.org>.
On Tue, Nov 21, 2000 at 07:15:32PM -0000, trawick@locus.apache.org wrote:
> trawick     00/11/21 11:15:30
> 
>   Modified:    test     client.c server.c
>   Log:
>   updates to changed interfaces to apr_set_port(), apr_get_port(),
>   apr_set_ipaddr(), and apr_get_ipaddr()
>...
>   --- server.c	2000/11/19 14:24:18	1.20
>   +++ server.c	2000/11/21 19:15:27	1.21
>   @@ -73,7 +73,7 @@
>        const char *bind_to_ipaddr = NULL;
>        char *local_ipaddr, *remote_ipaddr;
>        apr_port_t local_port, remote_port;
>   -    apr_sockaddr_t *localsa = NULL;
>   +    apr_sockaddr_t *localsa = NULL, *remotesa;
>        apr_status_t stat;
>        int family = APR_UNSPEC;
>        char buf[128];
>   @@ -155,8 +155,8 @@
>        fprintf(stdout, "OK\n");
>    
>        if (!localsa) {
>   -        apr_set_port(sock, APR_LOCAL, 8021);
>            apr_get_sockaddr(&localsa, APR_LOCAL, sock);
>   +        apr_set_port(localsa, 8021);
>        }

This seems a bit wonky. The above code implies that an apr_get_sockaddr()
returns an address that is *attached* to the socket. That any changes to the
address will reflect within the socket.

That seems like it will introduce a number of subtle bugs.

- if people forget the attached state
- what happens when it gets passed elsewhere
- can it be used after the socket closes
- etc


Cheers,
-g

-- 
Greg Stein, http://www.lyra.org/