[Freeciv-Dev] (PR#13134) Block only for 2 seconds on connect to metaserv
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Subject: |
[Freeciv-Dev] (PR#13134) Block only for 2 seconds on connect to metaserver |
From: |
"Vasco Alexandre da Silva Costa" <vasc@xxxxxxxxxxxxxx> |
Date: |
Wed, 18 May 2005 06:36:23 -0700 |
Reply-to: |
bugs@xxxxxxxxxxx |
<URL: http://bugs.freeciv.org/Ticket/Display.html?id=13134 >
This bug was discovered when the metaserver failed during the weekend.
Patch attached. Untested with a failed metaserver, but should work.
Index: client/clinet.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/clinet.c,v
retrieving revision 1.116
diff -u -u -r1.116 clinet.c
--- client/clinet.c 28 Apr 2005 17:19:52 -0000 1.116
+++ client/clinet.c 18 May 2005 13:33:03 -0000
@@ -590,6 +590,8 @@
#ifdef HAVE_UNAME
struct utsname un;
#endif
+ fd_set readfs, writefs, exceptfs;
+ struct timeval tv;
urlpath = my_lookup_httpd(metaname, &metaport, METALIST_ADDR);//metaserver);
if (!urlpath) {
@@ -608,12 +610,37 @@
return NULL;
}
+ my_nonblock(s);
+
if(connect(s, (struct sockaddr *) &addr.sockaddr, sizeof(addr)) == -1) {
- (void) mystrlcpy(errbuf, mystrerror(), n_errbuf);
- my_closesocket(s);
+ if (errno != EINPROGRESS) {
+ (void) mystrlcpy(errbuf, mystrerror(), n_errbuf);
+ my_closesocket(s);
+ return NULL;
+ }
+ }
+
+ tv.tv_sec = 2;
+ tv.tv_usec = 0;
+
+ FD_ZERO(&readfs);
+ FD_ZERO(&writefs);
+ FD_ZERO(&exceptfs);
+
+ FD_SET(s, &readfs);
+ FD_SET(s, &writefs);
+ FD_SET(s, &exceptfs);
+
+ if (select(s+1, &readfs, &writefs, &exceptfs, &tv) <= 0) {
return NULL;
}
+ if (FD_ISSET(s, &exceptfs)) {
+ return NULL;
+ }
+
+ my_block(s);
+
#ifdef HAVE_UNAME
uname(&un);
my_snprintf(machine_string,sizeof(machine_string),
Index: server/scripting/script_signal.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/scripting/script_signal.c,v
retrieving revision 1.8
diff -u -u -r1.8 script_signal.c
--- server/scripting/script_signal.c 11 May 2005 14:57:10 -0000 1.8
+++ server/scripting/script_signal.c 18 May 2005 13:33:03 -0000
@@ -222,8 +222,10 @@
signal_callback_list_unlink_all(signal->callbacks);
signal_callback_list_free(signal->callbacks);
- free(signal);
+ hash_delete_entry(signals, name);
+
+ free(signal);
free(name);
} else {
freelog(LOG_ERROR, "Signal \"%s\" does not exist, so cannot be freed.",
Index: utility/netintf.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/utility/netintf.c,v
retrieving revision 1.27
diff -u -u -r1.27 netintf.c
--- utility/netintf.c 22 Feb 2005 01:15:59 -0000 1.27
+++ utility/netintf.c 18 May 2005 13:33:03 -0000
@@ -158,6 +158,38 @@
#endif
}
+/***************************************************************
+ Set socket to blocking.
+***************************************************************/
+void my_block(int sockfd)
+{
+#ifdef NONBLOCKING_SOCKETS
+#ifdef HAVE_FCNTL
+ int f_set;
+
+ if ((f_set=fcntl(sockfd, F_GETFL)) == -1) {
+ freelog(LOG_ERROR, "fcntl F_GETFL failed: %s", mystrerror());
+ }
+
+ f_set &= ~O_NONBLOCK;
+
+ if (fcntl(sockfd, F_SETFL, f_set) == -1) {
+ freelog(LOG_ERROR, "fcntl F_SETFL failed: %s", mystrerror());
+ }
+#else
+#ifdef HAVE_IOCTL
+ long value=0;
+
+ if (ioctl(sockfd, FIONBIO, (char*)&value) == -1) {
+ freelog(LOG_ERROR, "ioctl failed: %s", mystrerror());
+ }
+#endif
+#endif
+#else
+ freelog(LOG_DEBUG, "NONBLOCKING_SOCKETS not available");
+#endif
+}
+
/***************************************************************************
Look up the service at hostname:port and fill in *sa.
***************************************************************************/
Index: utility/netintf.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/utility/netintf.h,v
retrieving revision 1.12
diff -u -u -r1.12 netintf.h
--- utility/netintf.h 4 Oct 2004 04:37:34 -0000 1.12
+++ utility/netintf.h 18 May 2005 13:33:03 -0000
@@ -61,6 +61,7 @@
void my_shutdown_network(void);
void my_nonblock(int sockfd);
+void my_block(int sockfd);
bool net_lookup_service(const char *name, int port,
union my_sockaddr *addr);
fz_FILE *my_querysocket(int sock, void *buf, size_t size);
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Freeciv-Dev] (PR#13134) Block only for 2 seconds on connect to metaserver,
Vasco Alexandre da Silva Costa <=
|
|