comparison stream/tcp.c @ 27461:5a30f5bc23a0

Rename HAVE_WINSOCK preprocessor condition to HAVE_WINSOCK_H. This is what it is called in FFmpeg and more consistent with other names for similar conditionals. This fixes a potential compilation failure on MinGW, as described in Bugzilla #1262.
author diego
date Fri, 29 Aug 2008 20:05:08 +0000
parents d788e177a35e
children be85aae103f2
comparison
equal deleted inserted replaced
27460:1b5516898adb 27461:5a30f5bc23a0
18 #include "config.h" 18 #include "config.h"
19 19
20 #include "mp_msg.h" 20 #include "mp_msg.h"
21 #include "help_mp.h" 21 #include "help_mp.h"
22 22
23 #ifndef HAVE_WINSOCK2 23 #ifndef HAVE_WINSOCK2_H
24 #include <netdb.h> 24 #include <netdb.h>
25 #include <netinet/in.h> 25 #include <netinet/in.h>
26 #include <sys/socket.h> 26 #include <sys/socket.h>
27 #include <arpa/inet.h> 27 #include <arpa/inet.h>
28 #define closesocket close 28 #define closesocket close
73 size_t server_address_size; 73 size_t server_address_size;
74 void *our_s_addr; // Pointer to sin_addr or sin6_addr 74 void *our_s_addr; // Pointer to sin_addr or sin6_addr
75 struct hostent *hp=NULL; 75 struct hostent *hp=NULL;
76 char buf[255]; 76 char buf[255];
77 77
78 #ifdef HAVE_WINSOCK2 78 #ifdef HAVE_WINSOCK2_H
79 u_long val; 79 u_long val;
80 int to; 80 int to;
81 #else 81 #else
82 struct timeval to; 82 struct timeval to;
83 #endif 83 #endif
89 // mp_msg(MSGT_NETWORK,MSGL_ERR,"Failed to create %s socket:\n", af2String(af)); 89 // mp_msg(MSGT_NETWORK,MSGL_ERR,"Failed to create %s socket:\n", af2String(af));
90 return TCP_ERROR_FATAL; 90 return TCP_ERROR_FATAL;
91 } 91 }
92 92
93 #if defined(SO_RCVTIMEO) && defined(SO_SNDTIMEO) 93 #if defined(SO_RCVTIMEO) && defined(SO_SNDTIMEO)
94 #ifdef HAVE_WINSOCK2 94 #ifdef HAVE_WINSOCK2_H
95 /* timeout in milliseconds */ 95 /* timeout in milliseconds */
96 to = 10 * 1000; 96 to = 10 * 1000;
97 #else 97 #else
98 to.tv_sec = 10; 98 to.tv_sec = 10;
99 to.tv_usec = 0; 99 to.tv_usec = 0;
113 } 113 }
114 114
115 115
116 memset(&server_address, 0, sizeof(server_address)); 116 memset(&server_address, 0, sizeof(server_address));
117 117
118 #ifndef HAVE_WINSOCK2 118 #ifndef HAVE_WINSOCK2_H
119 #ifdef HAVE_ATON 119 #ifdef HAVE_ATON
120 if (inet_aton(host, our_s_addr)!=1) 120 if (inet_aton(host, our_s_addr)!=1)
121 #else 121 #else
122 if (inet_pton(af, host, our_s_addr)!=1) 122 if (inet_pton(af, host, our_s_addr)!=1)
123 #endif 123 #endif
137 return TCP_ERROR_FATAL; 137 return TCP_ERROR_FATAL;
138 } 138 }
139 139
140 memcpy( our_s_addr, (void*)hp->h_addr_list[0], hp->h_length ); 140 memcpy( our_s_addr, (void*)hp->h_addr_list[0], hp->h_length );
141 } 141 }
142 #ifdef HAVE_WINSOCK2 142 #ifdef HAVE_WINSOCK2_H
143 else { 143 else {
144 unsigned long addr = inet_addr(host); 144 unsigned long addr = inet_addr(host);
145 memcpy( our_s_addr, (void*)&addr, sizeof(addr) ); 145 memcpy( our_s_addr, (void*)&addr, sizeof(addr) );
146 } 146 }
147 #endif 147 #endif
162 default: 162 default:
163 mp_msg(MSGT_NETWORK,MSGL_ERR, MSGTR_MPDEMUX_NW_UnknownAF, af); 163 mp_msg(MSGT_NETWORK,MSGL_ERR, MSGTR_MPDEMUX_NW_UnknownAF, af);
164 return TCP_ERROR_FATAL; 164 return TCP_ERROR_FATAL;
165 } 165 }
166 166
167 #if defined(HAVE_ATON) || defined(HAVE_WINSOCK2) 167 #if defined(HAVE_ATON) || defined(HAVE_WINSOCK2_H)
168 strncpy( buf, inet_ntoa( *((struct in_addr*)our_s_addr) ), 255); 168 strncpy( buf, inet_ntoa( *((struct in_addr*)our_s_addr) ), 255);
169 #else 169 #else
170 inet_ntop(af, our_s_addr, buf, 255); 170 inet_ntop(af, our_s_addr, buf, 255);
171 #endif 171 #endif
172 if(verb) mp_msg(MSGT_NETWORK,MSGL_STATUS,MSGTR_MPDEMUX_NW_ConnectingToServer, host, buf , port ); 172 if(verb) mp_msg(MSGT_NETWORK,MSGL_STATUS,MSGTR_MPDEMUX_NW_ConnectingToServer, host, buf , port );
173 173
174 // Turn the socket as non blocking so we can timeout on the connection 174 // Turn the socket as non blocking so we can timeout on the connection
175 #ifndef HAVE_WINSOCK2 175 #ifndef HAVE_WINSOCK2_H
176 fcntl( socket_server_fd, F_SETFL, fcntl(socket_server_fd, F_GETFL) | O_NONBLOCK ); 176 fcntl( socket_server_fd, F_SETFL, fcntl(socket_server_fd, F_GETFL) | O_NONBLOCK );
177 #else 177 #else
178 val = 1; 178 val = 1;
179 ioctlsocket( socket_server_fd, FIONBIO, &val ); 179 ioctlsocket( socket_server_fd, FIONBIO, &val );
180 #endif 180 #endif
181 if( connect( socket_server_fd, (struct sockaddr*)&server_address, server_address_size )==-1 ) { 181 if( connect( socket_server_fd, (struct sockaddr*)&server_address, server_address_size )==-1 ) {
182 #ifndef HAVE_WINSOCK2 182 #ifndef HAVE_WINSOCK2_H
183 if( errno!=EINPROGRESS ) { 183 if( errno!=EINPROGRESS ) {
184 #else 184 #else
185 if( (WSAGetLastError() != WSAEINPROGRESS) && (WSAGetLastError() != WSAEWOULDBLOCK) ) { 185 if( (WSAGetLastError() != WSAEINPROGRESS) && (WSAGetLastError() != WSAEWOULDBLOCK) ) {
186 #endif 186 #endif
187 if(verb) mp_msg(MSGT_NETWORK,MSGL_ERR,MSGTR_MPDEMUX_NW_CantConnect2Server, af2String(af)); 187 if(verb) mp_msg(MSGT_NETWORK,MSGL_ERR,MSGTR_MPDEMUX_NW_CantConnect2Server, af2String(af));
209 tv.tv_usec = 500000; 209 tv.tv_usec = 500000;
210 } 210 }
211 if (ret < 0) mp_msg(MSGT_NETWORK,MSGL_ERR,MSGTR_MPDEMUX_NW_SelectFailed); 211 if (ret < 0) mp_msg(MSGT_NETWORK,MSGL_ERR,MSGTR_MPDEMUX_NW_SelectFailed);
212 212
213 // Turn back the socket as blocking 213 // Turn back the socket as blocking
214 #ifndef HAVE_WINSOCK2 214 #ifndef HAVE_WINSOCK2_H
215 fcntl( socket_server_fd, F_SETFL, fcntl(socket_server_fd, F_GETFL) & ~O_NONBLOCK ); 215 fcntl( socket_server_fd, F_SETFL, fcntl(socket_server_fd, F_GETFL) & ~O_NONBLOCK );
216 #else 216 #else
217 val = 0; 217 val = 0;
218 ioctlsocket( socket_server_fd, FIONBIO, &val ); 218 ioctlsocket( socket_server_fd, FIONBIO, &val );
219 #endif 219 #endif