- /* For the moment, not getting a nonblocking mode will note be fatal */
- if (ptr->flags & MEM_NO_BLOCK)
- {
- int flags;
-
- flags= fcntl(ptr->hosts[x].fd, F_GETFL, 0);
- if (flags != -1)
- (void)fcntl(ptr->hosts[x].fd, F_SETFL, flags | O_NONBLOCK);
+ addrlen= strlen(servAddr.sun_path) + sizeof(servAddr.sun_family);
+
+test_connect:
+ if (connect(ptr->fd,
+ (struct sockaddr *)&servAddr,
+ sizeof(servAddr)) < 0)
+ {
+ switch (errno) {
+ case EINPROGRESS:
+ {
+ struct timeval tm = { ptr->root->connect_timeout, 0 };
+ socklen_t len= sizeof(int);
+ fd_set wset;
+ int error=0, value;
+
+ FD_ZERO(&wset);
+ FD_SET(ptr->fd, &wset);
+
+ select(ptr->fd+1, NULL, &wset, NULL, &tm);
+ if (FD_ISSET(ptr->fd, &wset) != 0)
+ {
+ if (getsockopt(ptr->fd, SOL_SOCKET, SO_ERROR, &value, &len) == 0)
+ {
+ if (value)
+ {
+ error= 1;
+ }
+ }
+ else
+ {
+ error= 1;
+ }
+ }
+ else
+ {
+ error= 1;
+ }
+
+ if (error)
+ {
+ ptr->cached_errno= errno;
+ WATCHPOINT_ERRNO(ptr->cached_errno);
+ close(ptr->fd);
+ ptr->fd= -1;
+ return MEMCACHED_ERRNO;
+ }
+
+ break;
+ }
+ /* We are spinning waiting on connect */
+ case EALREADY:
+ case EINTR:
+ goto test_connect;
+ case EISCONN: /* We were spinning waiting on connect */
+ break;
+ default:
+ WATCHPOINT_ERRNO(errno);
+ ptr->cached_errno= errno;
+ return MEMCACHED_ERRNO;