aboutsummaryrefslogtreecommitdiff
path: root/pd/src/t_tkcmd.c
diff options
context:
space:
mode:
authorGuenter Geiger <ggeiger@users.sourceforge.net>2002-12-09 18:30:29 +0000
committerGuenter Geiger <ggeiger@users.sourceforge.net>2002-12-09 18:30:29 +0000
commit011312406096edae98aeb079a12932f2b720e10b (patch)
tree862b717c3b0a7a8fd575301f223df2dc0e68291f /pd/src/t_tkcmd.c
parentb28e8e9e7aea1451a7bd5946dc3e4331e44ba514 (diff)
This commit was generated by cvs2svn to compensate for changes in r284,
which included commits to RCS files with non-trunk default branches. svn path=/trunk/; revision=285
Diffstat (limited to 'pd/src/t_tkcmd.c')
-rw-r--r--pd/src/t_tkcmd.c41
1 files changed, 36 insertions, 5 deletions
diff --git a/pd/src/t_tkcmd.c b/pd/src/t_tkcmd.c
index 3415691b..a862beda 100644
--- a/pd/src/t_tkcmd.c
+++ b/pd/src/t_tkcmd.c
@@ -168,7 +168,11 @@ void pdgui_setupsocket(void)
{
struct sockaddr_in server;
struct hostent *hp;
-
+#ifdef UNIX
+ int retry = 10;
+#else
+ int retry = 1;
+#endif
#ifdef NT
short version = MAKEWORD(2, 0);
WSADATA nobby;
@@ -197,14 +201,41 @@ void pdgui_setupsocket(void)
server.sin_port = htons((unsigned short)portno);
/* try to connect */
- if (connect(sockfd, (struct sockaddr *) &server, sizeof (server)) < 0)
- pdgui_sockerror("connecting stream socket");
-
+ while (1)
+ {
+ if (connect(sockfd, (struct sockaddr *) &server, sizeof (server)) >= 0)
+ goto gotit;
+ retry--;
+ if (retry <= 0)
+ break;
+ /* In UNIX there's a race condition; the child won't be
+ able to connect before the parent (pd) has shed its
+ setuid-ness. In case this is the problem, sleep and
+ retry. */
+ else
+ {
+#ifdef UNIX
+ fd_set readset, writeset, exceptset;
+ struct timeval timout;
+
+ timout.tv_sec = 0;
+ timout.tv_usec = 100000;
+ FD_ZERO(&writeset);
+ FD_ZERO(&readset);
+ FD_ZERO(&exceptset);
+ fprintf(stderr, "retrying connect...\n");
+ if (select(1, &readset, &writeset, &exceptset, &timout) < 0)
+ perror("select");
+#endif /* UNIX */
+ }
+ }
+ pdgui_sockerror("connecting stream socket");
+gotit: ;
#ifdef UNIX
/* in unix we ask TK to call us back. In NT we have to poll. */
Tk_CreateFileHandler(sockfd, TK_READABLE | TK_EXCEPTION,
pd_readsocket, 0);
-#endif
+#endif /* UNIX */
}
/**************************** commands ************************/