Update of /cvsroot/playerstage/code/player/libplayertcp
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21813/libplayertcp

Modified Files:
        playertcp.cc playertcp.h socket_util.c 
Log Message:
tweaks to allow auto-assignment of ports

Index: playertcp.h
===================================================================
RCS file: /cvsroot/playerstage/code/player/libplayertcp/playertcp.h,v
retrieving revision 1.25
retrieving revision 1.26
diff -C2 -d -r1.25 -r1.26
*** playertcp.h 21 Sep 2007 21:41:00 -0000      1.25
--- playertcp.h 24 Sep 2007 20:43:41 -0000      1.26
***************
*** 145,149 ****
      pthread_t thread;
  
!     int Listen(int* ports, int num_ports);
      int Listen(int port);
      QueuePointer AddClient(struct sockaddr_in* cliaddr, 
--- 145,149 ----
      pthread_t thread;
  
!     int Listen(int* ports, int num_ports, int* new_ports=NULL);
      int Listen(int port);
      QueuePointer AddClient(struct sockaddr_in* cliaddr, 

Index: playertcp.cc
===================================================================
RCS file: /cvsroot/playerstage/code/player/libplayertcp/playertcp.cc,v
retrieving revision 1.63
retrieving revision 1.64
diff -C2 -d -r1.63 -r1.64
*** playertcp.cc        21 Sep 2007 22:02:06 -0000      1.63
--- playertcp.cc        24 Sep 2007 20:43:41 -0000      1.64
***************
*** 165,169 ****
  
  int
! PlayerTCP::Listen(int* ports, int num_ports)
  {
    int tmp = this->num_listeners;
--- 165,169 ----
  
  int
! PlayerTCP::Listen(int* ports, int num_ports, int* new_ports)
  {
    int tmp = this->num_listeners;
***************
*** 180,191 ****
    for(int i=tmp;i<this->num_listeners;i++)
    {
      if((this->listeners[i].fd =
!         create_and_bind_socket(1,this->host,ports+i,
!                                PLAYER_TRANSPORT_TCP,200)) < 0)
      {
        PLAYER_ERROR("create_and_bind_socket() failed");
        return(-1);
      }
!     this->listeners[i].port = ports[i];
  
      // set up for later use of poll() to accept() connections on this port
--- 180,193 ----
    for(int i=tmp;i<this->num_listeners;i++)
    {
+     int p = ports[i];
      if((this->listeners[i].fd =
!         create_and_bind_socket(1,this->host,&p,PLAYER_TRANSPORT_TCP,200)) < 0)
      {
        PLAYER_ERROR("create_and_bind_socket() failed");
        return(-1);
      }
!     if(new_ports)
!       new_ports[i] = p;
!     this->listeners[i].port = p;
  
      // set up for later use of poll() to accept() connections on this port

Index: socket_util.c
===================================================================
RCS file: /cvsroot/playerstage/code/player/libplayertcp/socket_util.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** socket_util.c       21 Sep 2007 22:02:06 -0000      1.4
--- socket_util.c       24 Sep 2007 20:43:41 -0000      1.5
***************
*** 91,94 ****
--- 91,95 ----
  
    struct sockaddr_in serverp;
+   socklen_t serverp_len;
  
    int socktype;
***************
*** 184,190 ****
    }
  
-   // Copy back the selected port (in case the OS changed it)
-   *portnum = ntohs(serverp.sin_port);
- 
    /* if it's TCP, go ahead with listen() */
    if(socktype == SOCK_STREAM)
--- 185,188 ----
***************
*** 198,201 ****
--- 196,212 ----
    }
  
+   memset(&serverp,0,sizeof(serverp));
+   serverp_len = sizeof(serverp);
+ 
+   // Copy back the selected port (in case the OS changed it)
+   if(getsockname(sock,(struct sockaddr*)&serverp, &serverp_len) == -1)
+     perror("create_and_bind_socket():getsockname failed; continuing.");
+   else
+   {
+     *portnum = ntohs(serverp.sin_port);
+     printf("listening on %d\n", *portnum);
+   }
+ 
+ 
    /*
     * return the fd for the newly bound socket 


-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Playerstage-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/playerstage-commit

Reply via email to