aboutsummaryrefslogtreecommitdiff
path: root/lib/security.c
diff options
context:
space:
mode:
authorJulien Chaffraix <julien.chaffraix@gmail.com>2010-09-10 00:17:17 -0700
committerDaniel Stenberg <daniel@haxx.se>2010-09-22 23:34:36 +0200
commit0006cdddee80718cb83aab0f1b544d79f1262159 (patch)
treeba13eb000390daffdc8ae2f537f34ea46ed45c5c /lib/security.c
parentb684ccd8b1c52098cd35c8284dc88db7b51772e7 (diff)
security.c: Made block_write return a CURLcode.
While doing so, renamed it to socket_write to better match its function.
Diffstat (limited to 'lib/security.c')
-rw-r--r--lib/security.c47
1 files changed, 28 insertions, 19 deletions
diff --git a/lib/security.c b/lib/security.c
index 952364272..e9f8ea02f 100644
--- a/lib/security.c
+++ b/lib/security.c
@@ -127,21 +127,30 @@ socket_read(curl_socket_t fd, void *to, size_t len)
return CURLE_OK;
}
-static int
-block_write(int fd, const void *buf, size_t len)
+
+/* Write |len| bytes from the buffer |to| to the socket |fd|. Return a
+ CURLcode saying whether an error occured or CURLE_OK if |len| was written. */
+static CURLcode
+socket_write(struct connectdata *conn, curl_socket_t fd, const void *to, size_t len)
{
- const unsigned char *p = buf;
- int b;
- while(len) {
- b = write(fd, p, len);
- if(b < 0 && (errno == EINTR || errno == EAGAIN))
- continue;
- else if(b < 0)
- return -1;
- len -= b;
- p += b;
+ const char *to_p = to;
+ CURLcode code;
+ ssize_t written;
+
+ while(len > 0) {
+ code = Curl_write_plain(conn, fd, to_p, len, &written);
+ if(code == CURLE_OK) {
+ len -= written;
+ to_p += written;
+ }
+ else {
+ /* FIXME: We are doing a busy wait */
+ if(code == CURLE_AGAIN)
+ continue;
+ return code;
+ }
}
- return p - (unsigned char*)buf;
+ return CURLE_OK;
}
static CURLcode read_data(struct connectdata *conn,
@@ -237,11 +246,11 @@ sec_send(struct connectdata *conn, int fd, const char *from, int length)
bytes = Curl_base64_encode(conn->data, (char *)buf, bytes, &cmdbuf);
if(bytes > 0) {
if(protlevel == prot_private)
- block_write(fd, "ENC ", 4);
+ socket_write(conn, fd, "ENC ", 4);
else
- block_write(fd, "MIC ", 4);
- block_write(fd, cmdbuf, bytes);
- block_write(fd, "\r\n", 2);
+ socket_write(conn, fd, "MIC ", 4);
+ socket_write(conn, fd, cmdbuf, bytes);
+ socket_write(conn, fd, "\r\n", 2);
Curl_infof(conn->data, "%s %s\n",
protlevel == prot_private ? "ENC" : "MIC", cmdbuf);
free(cmdbuf);
@@ -249,8 +258,8 @@ sec_send(struct connectdata *conn, int fd, const char *from, int length)
}
else {
bytes = htonl(bytes);
- block_write(fd, &bytes, sizeof(bytes));
- block_write(fd, buf, ntohl(bytes));
+ socket_write(conn, fd, &bytes, sizeof(bytes));
+ socket_write(conn, fd, buf, ntohl(bytes));
}
free(buf);
return length;