Commit 30335065 authored by Olivier Crête's avatar Olivier Crête
Browse files

pseudotcp: Make the error per thread

Ideally, this should be returned from each function call..
parent 99d7838a
......@@ -475,6 +475,8 @@ typedef enum {
typedef struct _PseudoTcpSource PseudoTcpSource;
static GPrivate pseudotcp_error;
struct _PseudoTcpSocketPrivate {
PseudoTcpCallbacks callbacks;
GDatagramBased *base_socket; /* owned */
......@@ -490,7 +492,6 @@ struct _PseudoTcpSocketPrivate {
Shutdown shutdown; /* only used if !support_fin_ack */
gboolean shutdown_reads;
gint error;
GInputStream *input_stream; /* owned; nullable */
GOutputStream *output_stream; /* owned; nullable */
......@@ -1057,7 +1058,6 @@ pseudo_tcp_socket_init (PseudoTcpSocket *obj)
g_rec_mutex_init (&priv->mutex);
priv->shutdown = SD_NONE;
priv->error = 0;
priv->rbuf_len = DEFAULT_RCV_BUF_SIZE;
pseudo_tcp_fifo_init (&priv->rbuf, priv->rbuf_len);
......@@ -1289,6 +1289,11 @@ pseudo_tcp_weak_ref_free (PseudoTcpSocketWeakRef *weak)
g_slice_free (PseudoTcpSocketWeakRef, weak);
}
static void
set_error (int error)
{
g_private_set (&pseudotcp_error, GINT_TO_POINTER(error));
}
static gboolean
pseudo_tcp_socket_listen_locked (PseudoTcpSocket *self)
......@@ -1296,7 +1301,7 @@ pseudo_tcp_socket_listen_locked (PseudoTcpSocket *self)
PseudoTcpSocketPrivate *priv = self->priv;
if (priv->state != TCP_LISTEN) {
priv->error = EINVAL;
set_error (EINVAL);
update_sources (self);
......@@ -1890,7 +1895,7 @@ pseudo_tcp_socket_recv(PseudoTcpSocket *self, char * buffer, size_t len)
/* Return ENOTCONN if FIN-ACK is not supported and the connection is not
* ESTABLISHED. */
if (!priv->support_fin_ack && priv->state != TCP_ESTABLISHED) {
priv->error = ENOTCONN;
set_error (ENOTCONN);
retval = -1;
goto done;
}
......@@ -1907,7 +1912,7 @@ pseudo_tcp_socket_recv(PseudoTcpSocket *self, char * buffer, size_t len)
!(pseudo_tcp_state_has_received_fin (priv->state) ||
pseudo_tcp_state_has_received_fin_ack (priv->state))) {
priv->bReadEnable = TRUE;
priv->error = EWOULDBLOCK;
set_error (EWOULDBLOCK);
retval = -1;
goto done;
}
......@@ -1947,7 +1952,7 @@ pseudo_tcp_socket_send(PseudoTcpSocket *self, const char * buffer, guint32 len)
g_rec_mutex_lock (&self->priv->mutex);
if (priv->state != TCP_ESTABLISHED) {
priv->error = pseudo_tcp_state_has_sent_fin (priv->state) ? EPIPE : ENOTCONN;
set_error (pseudo_tcp_state_has_sent_fin (priv->state) ? EPIPE : ENOTCONN);
retval = -1;
goto done;
}
......@@ -1956,7 +1961,7 @@ pseudo_tcp_socket_send(PseudoTcpSocket *self, const char * buffer, guint32 len)
if (!available_space) {
priv->bWriteEnable = TRUE;
priv->error = EWOULDBLOCK;
set_error (EWOULDBLOCK);
retval = -1;
goto done;
}
......@@ -2163,14 +2168,7 @@ pseudo_tcp_socket_close_finish (PseudoTcpSocket *self, GAsyncResult *res,
int
pseudo_tcp_socket_get_error(PseudoTcpSocket *self)
{
PseudoTcpSocketPrivate *priv = self->priv;
int error;
g_rec_mutex_lock (&self->priv->mutex);
error = priv->error;
g_rec_mutex_unlock (&self->priv->mutex);
return error;
return GPOINTER_TO_INT (g_private_get (&pseudotcp_error));
}
//
......@@ -3650,7 +3648,7 @@ set_state_closed (PseudoTcpSocket *self, guint32 err)
"Pseudo-TCP socket closed with error %u.", err);
pseudo_tcp_socket_close (self, TRUE);
priv->error = err;
set_error (err);
if (priv->tcp_clock_source) {
g_source_destroy (priv->tcp_clock_source);
......@@ -3728,8 +3726,10 @@ pseudo_tcp_socket_condition_check (PseudoTcpSocket *self,
!pseudo_tcp_state_has_sent_fin (priv->state))
retval |= G_IO_OUT;
#if 0
if (priv->error != 0 && priv->shutdown == SD_FORCEFUL)
retval |= G_IO_ERR;
#endif
g_rec_mutex_unlock (&self->priv->mutex);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment