changeset 15760:5dcc5524cb68

fix wrong usage of select() (based on patch by Selwyn Tang selwyn hectrix com), add missing closesocket calls.
author reimar
date Sun, 19 Jun 2005 12:42:36 +0000
parents 5c5381af2e3b
children f2e5268acebb
files libmpdemux/rtp.c
diffstat 1 files changed, 18 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/libmpdemux/rtp.c	Sun Jun 19 11:09:40 2005 +0000
+++ b/libmpdemux/rtp.c	Sun Jun 19 12:42:36 2005 +0000
@@ -76,7 +76,7 @@
 		hp =(struct hostent*)gethostbyname( url->hostname );
 		if( hp==NULL ) {
 			mp_msg(MSGT_NETWORK,MSGL_ERR,"Counldn't resolve name: %s\n", url->hostname);
-			return -1;
+			goto err_out;
 		}
 		memcpy( (void*)&server_address.sin_addr.s_addr, (void*)hp->h_addr, hp->h_length );
 #else
@@ -103,8 +103,7 @@
 		if( WSAGetLastError() != WSAEINPROGRESS ) {
 #endif
 			mp_msg(MSGT_NETWORK,MSGL_ERR,"Failed to connect to server\n");
-			closesocket(socket_server_fd);
-			return -1;
+			goto err_out;
 		}
 	}
 	
@@ -113,7 +112,7 @@
 		hp =(struct hostent*)gethostbyname( url->hostname );
 		if( hp==NULL ) {
 			mp_msg(MSGT_NETWORK,MSGL_ERR,"Counldn't resolve name: %s\n", url->hostname);
-			return -1;
+			goto err_out;
 		}
 		memcpy( (void*)&server_address.sin_addr.s_addr, (void*)hp->h_addr, hp->h_length );
 	} else {
@@ -134,7 +133,7 @@
 		mcast.imr_interface.s_addr = 0;
 		if( setsockopt( socket_server_fd, IPPROTO_IP, IP_ADD_MEMBERSHIP, &mcast, sizeof(mcast))) {
 			mp_msg(MSGT_NETWORK,MSGL_ERR,"IP_ADD_MEMBERSHIP failed (do you have multicasting enabled in your kernel?)\n");
-			return -1;
+			goto err_out;
 		}
 	}
 
@@ -142,18 +141,26 @@
 	tv.tv_usec = (1 * 1000000);	// 1 second timeout
 	FD_ZERO( &set );
 	FD_SET( socket_server_fd, &set );
-	if( select(socket_server_fd+1, &set, NULL, NULL, &tv)>0 ) {
-        //if( select(socket_server_fd+1, &set, NULL, NULL, NULL)>0 ) {
+	err = select(socket_server_fd+1, &set, NULL, NULL, &tv);
+	if (err < 0) {
+	  mp_msg(MSGT_NETWORK, MSGL_FATAL, "Select failed: %s\n", strerror(errno));
+	  goto err_out;
+	}
+	if (err == 0) {
+	  mp_msg(MSGT_NETWORK,MSGL_ERR,"Timeout! No data from host %s\n", url->hostname );
+	  goto err_out;
+	}
 		err_len = sizeof( err );
 		getsockopt( socket_server_fd, SOL_SOCKET, SO_ERROR, &err, &err_len );
 		if( err ) {
-			mp_msg(MSGT_NETWORK,MSGL_ERR,"Timeout! No data from host %s\n", url->hostname );
 			mp_msg(MSGT_NETWORK,MSGL_DBG2,"Socket error: %d\n", err );
-			closesocket(socket_server_fd);
-			return -1;
+			goto err_out;
 		}
-	}
 	return socket_server_fd;
+
+err_out:
+  closesocket(socket_server_fd);
+  return -1;	
 }
 
 static int rtp_streaming_read( int fd, char *buffer, int size, streaming_ctrl_t *streaming_ctrl ) {