(fhandler_socket::is_connect_pending): Ditto.
(fhandler_socket::is_connected): Ditto.
(fhandler_socket::set_connect_state): New method.
(struct select_record): Add member `except_on_write'.
(select_record::select_record): Initialize all bool values to `false'.
* fhandler_socket.cc: Use set_connect_state() method throughout.
(fhandler_socket::connect): Set state always to connected if connection
isn't pending.
* net.cc (cygwin_getsockopt): Revert erroneous previous patch.
* select.cc (set_bits): Check for `except_on_write'. Set fd in
write_fds if set. Set connect state to connected if fd has been
returned by WINSOCK_SELECT.
(peek_socket): Check for `except_on_write'.
(start_thread_socket): Ditto.
(fhandler_socket::select_write): Don't set `write_ready' if connect
is pending. Set `except_on_write' if connect is pending.
+2002-07-05 Corinna Vinschen <corinna@vinschen.de>
+
+ * fhandler.h (fhandler_socket::is_unconnected): Constify.
+ (fhandler_socket::is_connect_pending): Ditto.
+ (fhandler_socket::is_connected): Ditto.
+ (fhandler_socket::set_connect_state): New method.
+ (struct select_record): Add member `except_on_write'.
+ (select_record::select_record): Initialize all bool values to `false'.
+ * fhandler_socket.cc: Use set_connect_state() method throughout.
+ (fhandler_socket::connect): Set state always to connected if connection
+ isn't pending.
+ * net.cc (cygwin_getsockopt): Revert erroneous previous patch.
+ * select.cc (set_bits): Check for `except_on_write'. Set fd in
+ write_fds if set. Set connect state to connected if fd has been
+ returned by WINSOCK_SELECT.
+ (peek_socket): Check for `except_on_write'.
+ (start_thread_socket): Ditto.
+ (fhandler_socket::select_write): Don't set `write_ready' if connect
+ is pending. Set `except_on_write' if connect is pending.
+
2002-07-05 Christopher Faylor <cgf@redhat.com>
* ntdll.h (_SYSTEM_PROCESSOR_TIMES): Force eight byte alignment.
void set_shutdown_read () {FHSETF (SHUTRD);}
void set_shutdown_write () {FHSETF (SHUTWR);}
- bool is_unconnected () {return had_connect_or_listen == UNCONNECTED;}
- bool is_connect_pending () {return had_connect_or_listen == CONNECT_PENDING;}
- bool is_connected () {return had_connect_or_listen == CONNECTED;}
+ bool is_unconnected () const {return had_connect_or_listen == UNCONNECTED;}
+ bool is_connect_pending () const {return had_connect_or_listen == CONNECT_PENDING;}
+ bool is_connected () const {return had_connect_or_listen == CONNECTED;}
+ void set_connect_state (int newstate) { had_connect_or_listen = newstate; }
int bind (const struct sockaddr *name, int namelen);
int connect (const struct sockaddr *name, int namelen);
bool windows_handle;
bool read_ready, write_ready, except_ready;
bool read_selected, write_selected, except_selected;
+ bool except_on_write;
int (*startup) (select_record *me, class select_stuff *stuff);
int (*peek) (select_record *, bool);
int (*verify) (select_record *me, fd_set *readfds, fd_set *writefds,
struct select_record *next;
select_record (fhandler_base *in_fh = NULL) : fd (0), h (NULL),
- fh (in_fh), saw_error (0), windows_handle (0),
- read_ready (0), write_ready (0), except_ready (0),
- read_selected (0), write_selected (0), except_selected (0),
+ fh (in_fh), saw_error (false), windows_handle (false),
+ read_ready (false), write_ready (false), except_ready (false),
+ read_selected (false), write_selected (false),
+ except_selected (false), except_on_write (false),
startup (NULL), peek (NULL), verify (NULL), cleanup (NULL),
next (NULL) {}
};
}
}
- if (!res)
- had_connect_or_listen = CONNECTED;
- else if (WSAGetLastError () == WSAEINPROGRESS)
- had_connect_or_listen = CONNECT_PENDING;
+ if (WSAGetLastError () == WSAEINPROGRESS)
+ set_connect_state (CONNECT_PENDING);
+ else
+ set_connect_state (CONNECTED);
return res;
}
if (res)
set_winsock_errno ();
else
- had_connect_or_listen = CONNECTED;
+ set_connect_state (CONNECTED);
return res;
}
if (optname == SO_ERROR)
{
int *e = (int *) optval;
- if (!*e && fh->is_connect_pending ())
- *e = WSAEINPROGRESS;
*e = find_winsock_errno (*e);
}
if (me->write_selected && me->write_ready)
{
UNIX_FD_SET (me->fd, writefds);
+ if (me->except_on_write && me->fh->get_device () == FH_SOCKET)
+ ((fhandler_socket *) me->fh)->set_connect_state (CONNECTED);
ready++;
}
- if (me->except_selected && me->except_ready)
+ if ((me->except_selected || me->except_on_write) && me->except_ready)
{
- UNIX_FD_SET (me->fd, exceptfds);
+ if (me->except_on_write) /* Only on sockets */
+ {
+ UNIX_FD_SET (me->fd, writefds);
+ if (me->fh->get_device () == FH_SOCKET)
+ ((fhandler_socket *) me->fh)->set_connect_state (CONNECTED);
+ }
+ if (me->except_selected)
+ UNIX_FD_SET (me->fd, exceptfds);
ready++;
}
select_printf ("ready %d", ready);
me->fd);
WINSOCK_FD_SET (h, &ws_writefds);
}
- if (me->except_selected && !me->except_ready)
+ if ((me->except_selected || me->except_on_write) && !me->except_ready)
{
select_printf ("adding except fd_set %s, fd %d", me->fh->get_name (),
me->fd);
int r;
if ((me->read_selected && !me->read_ready)
|| (me->write_selected && !me->write_ready)
- || (me->except_selected && !me->except_ready))
+ || ((me->except_selected || me->except_on_write) && !me->except_ready))
{
r = WINSOCK_SELECT (0, &ws_readfds, &ws_writefds, &ws_exceptfds, &tv);
select_printf ("WINSOCK_SELECT returned %d", r);
me->read_ready = true;
if (WINSOCK_FD_ISSET (h, &ws_writefds) || (me->write_selected && me->write_ready))
me->write_ready = true;
- if (WINSOCK_FD_ISSET (h, &ws_exceptfds) || (me->except_selected && me->except_ready))
+ if (WINSOCK_FD_ISSET (h, &ws_exceptfds) || ((me->except_selected || me->except_on_write) && me->except_ready))
me->except_ready = true;
}
return me->read_ready || me->write_ready || me->except_ready;
WINSOCK_FD_SET (h, &si->writefds);
select_printf ("Added to writefds");
}
- if (s->except_selected && !s->except_ready)
+ if ((s->except_selected || s->except_on_write) && !s->except_ready)
{
WINSOCK_FD_SET (h, &si->exceptfds);
select_printf ("Added to exceptfds");
s->cleanup = socket_cleanup;
}
s->peek = peek_socket;
- s->write_ready = saw_shutdown_write () || !is_connected ();
+ s->write_ready = saw_shutdown_write () || is_unconnected ();
s->write_selected = true;
+ if (is_connect_pending ())
+ {
+ s->except_ready = saw_shutdown_write () || saw_shutdown_read ();
+ s->except_on_write = true;
+ }
return s;
}