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 { ...@@ -475,6 +475,8 @@ typedef enum {
typedef struct _PseudoTcpSource PseudoTcpSource; typedef struct _PseudoTcpSource PseudoTcpSource;
static GPrivate pseudotcp_error;
struct _PseudoTcpSocketPrivate { struct _PseudoTcpSocketPrivate {
PseudoTcpCallbacks callbacks; PseudoTcpCallbacks callbacks;
GDatagramBased *base_socket; /* owned */ GDatagramBased *base_socket; /* owned */
...@@ -490,7 +492,6 @@ struct _PseudoTcpSocketPrivate { ...@@ -490,7 +492,6 @@ struct _PseudoTcpSocketPrivate {
Shutdown shutdown; /* only used if !support_fin_ack */ Shutdown shutdown; /* only used if !support_fin_ack */
gboolean shutdown_reads; gboolean shutdown_reads;
gint error;
GInputStream *input_stream; /* owned; nullable */ GInputStream *input_stream; /* owned; nullable */
GOutputStream *output_stream; /* owned; nullable */ GOutputStream *output_stream; /* owned; nullable */
...@@ -1057,7 +1058,6 @@ pseudo_tcp_socket_init (PseudoTcpSocket *obj) ...@@ -1057,7 +1058,6 @@ pseudo_tcp_socket_init (PseudoTcpSocket *obj)
g_rec_mutex_init (&priv->mutex); g_rec_mutex_init (&priv->mutex);
priv->shutdown = SD_NONE; priv->shutdown = SD_NONE;
priv->error = 0;
priv->rbuf_len = DEFAULT_RCV_BUF_SIZE; priv->rbuf_len = DEFAULT_RCV_BUF_SIZE;
pseudo_tcp_fifo_init (&priv->rbuf, priv->rbuf_len); pseudo_tcp_fifo_init (&priv->rbuf, priv->rbuf_len);
...@@ -1289,6 +1289,11 @@ pseudo_tcp_weak_ref_free (PseudoTcpSocketWeakRef *weak) ...@@ -1289,6 +1289,11 @@ pseudo_tcp_weak_ref_free (PseudoTcpSocketWeakRef *weak)
g_slice_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 static gboolean
pseudo_tcp_socket_listen_locked (PseudoTcpSocket *self) pseudo_tcp_socket_listen_locked (PseudoTcpSocket *self)
...@@ -1296,7 +1301,7 @@ pseudo_tcp_socket_listen_locked (PseudoTcpSocket *self) ...@@ -1296,7 +1301,7 @@ pseudo_tcp_socket_listen_locked (PseudoTcpSocket *self)
PseudoTcpSocketPrivate *priv = self->priv; PseudoTcpSocketPrivate *priv = self->priv;
if (priv->state != TCP_LISTEN) { if (priv->state != TCP_LISTEN) {
priv->error = EINVAL; set_error (EINVAL);
update_sources (self); update_sources (self);
...@@ -1890,7 +1895,7 @@ pseudo_tcp_socket_recv(PseudoTcpSocket *self, char * buffer, size_t len) ...@@ -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 /* Return ENOTCONN if FIN-ACK is not supported and the connection is not
* ESTABLISHED. */ * ESTABLISHED. */
if (!priv->support_fin_ack && priv->state != TCP_ESTABLISHED) { if (!priv->support_fin_ack && priv->state != TCP_ESTABLISHED) {
priv->error = ENOTCONN; set_error (ENOTCONN);
retval = -1; retval = -1;
goto done; goto done;
} }
...@@ -1907,7 +1912,7 @@ pseudo_tcp_socket_recv(PseudoTcpSocket *self, char * buffer, size_t len) ...@@ -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 (priv->state) ||
pseudo_tcp_state_has_received_fin_ack (priv->state))) { pseudo_tcp_state_has_received_fin_ack (priv->state))) {
priv->bReadEnable = TRUE; priv->bReadEnable = TRUE;
priv->error = EWOULDBLOCK; set_error (EWOULDBLOCK);
retval = -1; retval = -1;
goto done; goto done;
} }
...@@ -1947,7 +1952,7 @@ pseudo_tcp_socket_send(PseudoTcpSocket *self, const char * buffer, guint32 len) ...@@ -1947,7 +1952,7 @@ pseudo_tcp_socket_send(PseudoTcpSocket *self, const char * buffer, guint32 len)
g_rec_mutex_lock (&self->priv->mutex); g_rec_mutex_lock (&self->priv->mutex);
if (priv->state != TCP_ESTABLISHED) { 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; retval = -1;
goto done; goto done;
} }
...@@ -1956,7 +1961,7 @@ pseudo_tcp_socket_send(PseudoTcpSocket *self, const char * buffer, guint32 len) ...@@ -1956,7 +1961,7 @@ pseudo_tcp_socket_send(PseudoTcpSocket *self, const char * buffer, guint32 len)
if (!available_space) { if (!available_space) {
priv->bWriteEnable = TRUE; priv->bWriteEnable = TRUE;
priv->error = EWOULDBLOCK; set_error (EWOULDBLOCK);
retval = -1; retval = -1;
goto done; goto done;
} }
...@@ -2163,14 +2168,7 @@ pseudo_tcp_socket_close_finish (PseudoTcpSocket *self, GAsyncResult *res, ...@@ -2163,14 +2168,7 @@ pseudo_tcp_socket_close_finish (PseudoTcpSocket *self, GAsyncResult *res,
int int
pseudo_tcp_socket_get_error(PseudoTcpSocket *self) pseudo_tcp_socket_get_error(PseudoTcpSocket *self)
{ {
PseudoTcpSocketPrivate *priv = self->priv; return GPOINTER_TO_INT (g_private_get (&pseudotcp_error));
int error;
g_rec_mutex_lock (&self->priv->mutex);
error = priv->error;
g_rec_mutex_unlock (&self->priv->mutex);
return error;
} }
// //
...@@ -3650,7 +3648,7 @@ set_state_closed (PseudoTcpSocket *self, guint32 err) ...@@ -3650,7 +3648,7 @@ set_state_closed (PseudoTcpSocket *self, guint32 err)
"Pseudo-TCP socket closed with error %u.", err); "Pseudo-TCP socket closed with error %u.", err);
pseudo_tcp_socket_close (self, TRUE); pseudo_tcp_socket_close (self, TRUE);
priv->error = err; set_error (err);
if (priv->tcp_clock_source) { if (priv->tcp_clock_source) {
g_source_destroy (priv->tcp_clock_source); g_source_destroy (priv->tcp_clock_source);
...@@ -3728,8 +3726,10 @@ pseudo_tcp_socket_condition_check (PseudoTcpSocket *self, ...@@ -3728,8 +3726,10 @@ pseudo_tcp_socket_condition_check (PseudoTcpSocket *self,
!pseudo_tcp_state_has_sent_fin (priv->state)) !pseudo_tcp_state_has_sent_fin (priv->state))
retval |= G_IO_OUT; retval |= G_IO_OUT;
#if 0
if (priv->error != 0 && priv->shutdown == SD_FORCEFUL) if (priv->error != 0 && priv->shutdown == SD_FORCEFUL)
retval |= G_IO_ERR; retval |= G_IO_ERR;
#endif
g_rec_mutex_unlock (&self->priv->mutex); 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