Check SO_ERROR when async connect completes
When non-blocking connect completes the error code can be read using getsockopt(SO_ERROR). Doing this is important for identifying failure to connect, especially if POLLERR and POLLHUP were not employed by the user. The QEMU iscsi block driver does not use POLLERR/POLLHUP and depends on SO_ERROR to detect connection failure. Signed-off-by: Stefan Hajnoczi <stefanha@gmail.com>
This commit is contained in:
@@ -317,6 +317,22 @@ iscsi_service(struct iscsi_context *iscsi, int revents)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (iscsi->is_connected == 0 && iscsi->fd != -1 && revents&POLLOUT) {
|
if (iscsi->is_connected == 0 && iscsi->fd != -1 && revents&POLLOUT) {
|
||||||
|
int err = 0;
|
||||||
|
socklen_t err_size = sizeof(err);
|
||||||
|
|
||||||
|
if (getsockopt(iscsi->fd, SOL_SOCKET, SO_ERROR,
|
||||||
|
&err, &err_size) != 0 || err != 0) {
|
||||||
|
if (err == 0) {
|
||||||
|
err = errno;
|
||||||
|
}
|
||||||
|
iscsi_set_error(iscsi, "iscsi_service: socket error "
|
||||||
|
"%s(%d) while connecting.",
|
||||||
|
strerror(err), err);
|
||||||
|
iscsi->socket_status_cb(iscsi, SCSI_STATUS_ERROR,
|
||||||
|
NULL, iscsi->connect_data);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
iscsi->is_connected = 1;
|
iscsi->is_connected = 1;
|
||||||
iscsi->socket_status_cb(iscsi, SCSI_STATUS_GOOD, NULL,
|
iscsi->socket_status_cb(iscsi, SCSI_STATUS_GOOD, NULL,
|
||||||
iscsi->connect_data);
|
iscsi->connect_data);
|
||||||
|
|||||||
Reference in New Issue
Block a user