+
+ if (cs->event == CS_CONNECT)
+ {
+ int fd = cs->iofile;
+ fd_set input, output;
+ struct timeval tv;
+ int r;
+
+ tv.tv_sec = 0;
+ tv.tv_usec = 1;
+
+ FD_ZERO(&input);
+ FD_ZERO(&output);
+ FD_SET (fd, &input);
+ FD_SET (fd, &output);
+
+ r = select (fd+1, &input, &output, 0, &tv);
+ if (r > 0)
+ {
+ if (FD_ISSET(cs->iofile, &output))
+ {
+ cs->event = CS_DATA;
+ return 0; /* write OK, we're OK */
+ }
+ else
+ return -1; /* an error, for sure */
+ }
+ else if (r == 0)
+ return 0; /* timeout - incomplete */
+ }
+ return -1; /* wrong state or bad select */