summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Stenberg <daniel@haxx.se>2002-01-16 14:49:08 +0000
committerDaniel Stenberg <daniel@haxx.se>2002-01-16 14:49:08 +0000
commitdf01507582bf6b8e55ff2a5203121aa711f4f9bf (patch)
treee7c63e90ada4fc940fe9b072b1a798d5c5d9c745
parentf2bda5fd5bf0393ea5774d2417604672eedd2900 (diff)
downloadgnurl-df01507582bf6b8e55ff2a5203121aa711f4f9bf.tar.gz
gnurl-df01507582bf6b8e55ff2a5203121aa711f4f9bf.tar.bz2
gnurl-df01507582bf6b8e55ff2a5203121aa711f4f9bf.zip
Curl_read() and Curl_write() are both now adjusted to return properly in
cases where EWOULDBLOCK or equivalent is returned. We must not block.
-rw-r--r--lib/sendf.c47
1 files changed, 33 insertions, 14 deletions
diff --git a/lib/sendf.c b/lib/sendf.c
index afb6991d6..631c3f2a2 100644
--- a/lib/sendf.c
+++ b/lib/sendf.c
@@ -160,7 +160,7 @@ CURLcode Curl_sendf(int sockfd, struct connectdata *conn,
const char *fmt, ...)
{
struct SessionHandle *data = conn->data;
- size_t bytes_written;
+ ssize_t bytes_written;
CURLcode result;
char *s;
va_list ap;
@@ -187,25 +187,30 @@ CURLcode Curl_sendf(int sockfd, struct connectdata *conn,
*/
CURLcode Curl_write(struct connectdata *conn, int sockfd,
void *mem, size_t len,
- size_t *written)
+ ssize_t *written)
{
- size_t bytes_written;
+ ssize_t bytes_written;
#ifdef USE_SSLEAY
/* SSL_write() is said to return 'int' while write() and send() returns
'size_t' */
- int ssl_bytes;
if (conn->ssl.use) {
- int loop=100; /* just a precaution to never loop endlessly */
- while(loop--) {
- ssl_bytes = SSL_write(conn->ssl.handle, mem, len);
- if((0 >= ssl_bytes) ||
- (SSL_ERROR_WANT_WRITE != SSL_get_error(conn->ssl.handle,
- ssl_bytes) )) {
- /* this converts from signed to unsigned... */
- bytes_written = ssl_bytes;
- break;
+ int err;
+ int rc = SSL_write(conn->ssl.handle, mem, len);
+
+ if(rc < 0) {
+ err = SSL_get_error(conn->ssl.handle, rc);
+
+ switch(err) {
+ case SSL_ERROR_WANT_READ:
+ case SSL_ERROR_WANT_WRITE:
+ /* this is basicly the EWOULDBLOCK equivalent */
+ *written = 0;
+ return CURLE_OK;
}
+ /* a true error */
+ failf(conn->data, "SSL_write() return error %d\n", err);
+ return CURLE_WRITE_ERROR;
}
}
else {
@@ -216,13 +221,27 @@ CURLcode Curl_write(struct connectdata *conn, int sockfd,
}
else
#endif /* KRB4 */
+ {
bytes_written = swrite(sockfd, mem, len);
+ }
+ if(-1 == bytes_written) {
+#ifdef WIN32
+ if(EWOULDBLOCK == GetLastError())
+#else
+ if(EWOULDBLOCK == errno)
+#endif
+ {
+ /* this is just a case of EWOULDBLOCK */
+ *written=0;
+ return CURLE_OK;
+ }
+ }
#ifdef USE_SSLEAY
}
#endif
*written = bytes_written;
- return (bytes_written==len)?CURLE_OK:CURLE_WRITE_ERROR;
+ return (-1 != bytes_written)?CURLE_OK:CURLE_WRITE_ERROR;
}
/* client_write() sends data to the write callback(s)