summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNikos Mavrogiannopoulos <nmav@gnutls.org>2012-06-29 16:40:30 +0200
committerNikos Mavrogiannopoulos <nmav@gnutls.org>2012-06-29 16:43:01 +0200
commit744d5c815bd4fb0386bb945b77589f0b89167045 (patch)
tree1f0572e785f0bee3c57699558e21375aa1f60e31
parent180f1b31feeaa319c358be39f886b46a891749d9 (diff)
downloadgnutls-744d5c815bd4fb0386bb945b77589f0b89167045.tar.gz
cleaned up errno handling.
-rw-r--r--lib/gnutls_buffers.c55
1 files changed, 29 insertions, 26 deletions
diff --git a/lib/gnutls_buffers.c b/lib/gnutls_buffers.c
index afa5d306fb..74e2d92da6 100644
--- a/lib/gnutls_buffers.c
+++ b/lib/gnutls_buffers.c
@@ -155,6 +155,23 @@ int ret;
return ret;
}
+inline static
+int errno_to_gerr(int err)
+{
+ switch(err)
+ {
+ case EAGAIN:
+ return GNUTLS_E_AGAIN;
+ case EINTR:
+ return GNUTLS_E_INTERRUPTED;
+ case EMSGSIZE:
+ return GNUTLS_E_LARGE_PACKET;
+ default:
+ gnutls_assert ();
+ return GNUTLS_E_PUSH_ERROR;
+ }
+}
+
static ssize_t
_gnutls_dgram_read (gnutls_session_t session, mbuffer_st **bufel,
gnutls_pull_func pull_func)
@@ -186,20 +203,7 @@ _gnutls_dgram_read (gnutls_session_t session, mbuffer_st **bufel,
_gnutls_read_log ("READ: %d returned from %p, errno=%d gerrno=%d\n",
(int) i, fd, errno, session->internals.errnum);
- switch(err)
- {
- case EAGAIN:
- ret = GNUTLS_E_AGAIN;
- goto cleanup;
- case EINTR:
- ret = GNUTLS_E_INTERRUPTED;
- goto cleanup;
- case EMSGSIZE:
- ret = GNUTLS_E_LARGE_PACKET;
- default:
- gnutls_assert ();
- ret = GNUTLS_E_PULL_ERROR;
- }
+ ret = errno_to_gerr(err);
goto cleanup;
}
else
@@ -271,9 +275,7 @@ _gnutls_stream_read (gnutls_session_t session, mbuffer_st **bufel,
goto finish;
}
- if (err == EAGAIN)
- return GNUTLS_E_AGAIN;
- return GNUTLS_E_INTERRUPTED;
+ return errno_to_gerr(err);
}
else
{
@@ -346,6 +348,7 @@ _gnutls_writev_emu (gnutls_session_t session, gnutls_transport_ptr_t fd, const g
return ret;
}
+
static ssize_t
_gnutls_writev (gnutls_session_t session, const giovec_t * giovec,
int giovec_cnt)
@@ -364,15 +367,8 @@ _gnutls_writev (gnutls_session_t session, const giovec_t * giovec,
{
int err = get_errno (session);
_gnutls_debug_log ("errno: %d\n", err);
- if (err == EAGAIN)
- return GNUTLS_E_AGAIN;
- else if (err == EINTR)
- return GNUTLS_E_INTERRUPTED;
- else
- {
- gnutls_assert ();
- return GNUTLS_E_PUSH_ERROR;
- }
+
+ return errno_to_gerr(err);
}
return i;
}
@@ -590,6 +586,13 @@ _gnutls_io_write_flush (gnutls_session_t session)
(int) send_buffer->byte_length);
return ret;
}
+ else if (ret == GNUTLS_E_LARGE_PACKET)
+ {
+ _mbuffer_head_remove_bytes (send_buffer, tosend);
+ _gnutls_write_log ("WRITE cannot send large packet (%u bytes).\n",
+ (unsigned int) tosend);
+ return ret;
+ }
else
{
_gnutls_write_log ("WRITE error: code %d, %d bytes left.\n",