* dtable.cc (dtable::init_std_file_from_handle): Mention that console

handles are kernel objects since Windows 8.
	* fhandler.h (enum conn_state): Add "listener" state.
	(class fhandler_socket): Drop listener status flag.
	(fhandler_socket::lseek): Return -1 and errno ESPIPE.
	(fhandler_serial::lseek): Ditto.
	* fhandler_socket.cc (fhandler_socket::listen): Set connect_state to
	listener.  Add comment.
	(fhandler_socket::accept4): Explicitely check if the socket is listening
	and fail with EINVAL, if not.  Explain why we have to do that.
	(fhandler_socket::recv_internal): Explicitely check if the socket is
	connected if it's a stream socket.  Explain why we have to do that.
	(fhandler_socket::getpeereid): Drop now redundant test.
This commit is contained in:
Corinna Vinschen
2014-08-18 11:09:56 +00:00
parent 7e46c0af62
commit 1091d4404e
5 changed files with 55 additions and 20 deletions

View File

@ -77,7 +77,8 @@ enum conn_state
unconnected = 0,
connect_pending = 1,
connected = 2,
connect_failed = 3
listener = 3,
connect_failed = 4
};
enum line_edit_status
@ -528,12 +529,11 @@ class fhandler_socket: public fhandler_base
unsigned saw_shutdown_read : 1; /* Socket saw a SHUT_RD */
unsigned saw_shutdown_write : 1; /* Socket saw a SHUT_WR */
unsigned saw_reuseaddr : 1; /* Socket saw SO_REUSEADDR call */
unsigned listener : 1; /* listen called */
unsigned connect_state : 2;
public:
status_flags () :
async_io (0), saw_shutdown_read (0), saw_shutdown_write (0),
listener (0), connect_state (unconnected)
connect_state (unconnected)
{}
} status;
@ -554,7 +554,6 @@ class fhandler_socket: public fhandler_base
IMPLEMENT_STATUS_FLAG (bool, saw_shutdown_read)
IMPLEMENT_STATUS_FLAG (bool, saw_shutdown_write)
IMPLEMENT_STATUS_FLAG (bool, saw_reuseaddr)
IMPLEMENT_STATUS_FLAG (bool, listener)
IMPLEMENT_STATUS_FLAG (conn_state, connect_state)
int bind (const struct sockaddr *name, int namelen);
@ -582,7 +581,11 @@ class fhandler_socket: public fhandler_base
int ioctl (unsigned int cmd, void *);
int fcntl (int cmd, intptr_t);
off_t lseek (off_t, int) { return 0; }
off_t lseek (off_t, int)
{
set_errno (ESPIPE);
return -1;
}
int shutdown (int how);
int close ();
void hclose (HANDLE) {close ();}
@ -1135,9 +1138,12 @@ class fhandler_serial: public fhandler_base
int switch_modem_lines (int set, int clr);
int tcsetattr (int a, const struct termios *t);
int tcgetattr (struct termios *t);
off_t lseek (off_t, int) { return 0; }
off_t lseek (off_t, int)
{
set_errno (ESPIPE);
return -1;
}
int tcflush (int);
bool is_tty () const { return true; }
void fixup_after_fork (HANDLE parent);
void fixup_after_exec ();