summaryrefslogtreecommitdiff
path: root/lib
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:40:30 +0200
commitebc0ed0dbbea6926c9345653cf7d5ff4dbcc424f (patch)
tree8e5b281e48cc4a61bf82c9d31c5445718bf75e1f /lib
parent4ad2d65a531290119c6467c09683cb9678103207 (diff)
downloadgnutls-ebc0ed0dbbea6926c9345653cf7d5ff4dbcc424f.tar.gz
cleaned up errno handling.
Diffstat (limited to 'lib')
-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 cca3a187b8..5d1f3f50b3 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",