From: Andre Noll Date: Sun, 25 Nov 2007 09:59:29 +0000 (+0100) Subject: Get rid of E_RECV. X-Git-Tag: v0.3.0~93 X-Git-Url: http://git.tuebingen.mpg.de/?p=paraslash.git;a=commitdiff_plain;h=cd0abca282ec1cd29510f4cf8fefb04aa7e20ad7 Get rid of E_RECV. recv_bin_buffer() returns the converted errno on errors. So there's no point in having a paraslash error number for recv errors. --- diff --git a/afs.c b/afs.c index e84d9a88..09d42126 100644 --- a/afs.c +++ b/afs.c @@ -206,7 +206,7 @@ int send_callback_request(callback_function *f, struct osl_object *query, if (ret < 0) goto out; if (ret != sizeof(int)) { - ret = -E_RECV; + ret = -E_AFS_SHORT_READ; goto out; } ret = *(int *) buf; diff --git a/command.c b/command.c index ab948b09..c7d1c467 100644 --- a/command.c +++ b/command.c @@ -741,15 +741,15 @@ int handle_connect(int fd, struct sockaddr_in *addr) /* We can't use send_buffer here since buf may contain null bytes */ ret = send_bin_buffer(fd,(char *) crypt_buf, numbytes); if (ret < 0) - goto err_out; + goto net_err; /* recv decrypted number */ ret = recv_buffer(fd, buf, sizeof(buf)); if (ret < 0) - goto err_out; + goto net_err; numbytes = ret; ret = -E_AUTH; if (!numbytes) - goto err_out; + goto net_err; if (sscanf(buf, CHALLENGE_RESPONSE_MSG "%lu", &chall_response) < 1 || chall_response != challenge_nr) goto err_out; @@ -767,12 +767,14 @@ int handle_connect(int fd, struct sockaddr_in *addr) numbytes = strlen(buf); ret = send_bin_buffer(fd, buf, numbytes); if (ret < 0) - goto err_out; + goto net_err; if (use_rc4) enable_crypt(fd, rc4_recv, rc4_send, NULL); ret = read_command(fd, &command); - if (ret < 0) + if (ret == -E_COMMAND_SYNTAX) goto err_out; + if (ret < 0) + goto net_err; ret = -E_BAD_CMD; cmd = parse_cmd(command); if (!cmd) @@ -795,9 +797,9 @@ int handle_connect(int fd, struct sockaddr_in *addr) goto out; } err_out: + send_va_buffer(fd, "%s\n", PARA_STRERROR(-ret)); +net_err: PARA_NOTICE_LOG("%s\n", PARA_STRERROR(-ret)); - if (ret != -E_SEND && ret != -E_RECV) - send_va_buffer(fd, "%s\n", PARA_STRERROR(-ret)); ret = EXIT_FAILURE; out: free(command); diff --git a/error.h b/error.h index f1a3e41d..c420f490 100644 --- a/error.h +++ b/error.h @@ -86,6 +86,7 @@ extern const char **para_errlist[]; PARA_ERROR(AFS_SIGNAL, "afs caught deadly signal"), \ PARA_ERROR(AFS_SOCKET, "afs socket not writable"), \ PARA_ERROR(AFS_PARENT_DIED, "fatal: server process terminated"), \ + PARA_ERROR(AFS_SHORT_READ, "short read from afs socket"), \ #define MOOD_ERRORS \ @@ -173,7 +174,6 @@ extern const char **para_errlist[]; #define NET_ERRORS \ PARA_ERROR(SEND, "send error"), \ - PARA_ERROR(RECV, "receive error"), \ PARA_ERROR(SOCKET, "socket error"), \ PARA_ERROR(CONNECT, "connect error"), \ PARA_ERROR(ACCEPT, "accept error"), \ diff --git a/net.c b/net.c index c7bb8b4b..2991b6db 100644 --- a/net.c +++ b/net.c @@ -203,12 +203,10 @@ __printf_2_3 int send_va_buffer(int fd, const char *fmt, ...) * \param buf the buffer to write the decrypted data to * \param size the size of \a buf * - * Receive at most \a size bytes from filedescriptor fd. If encryption is + * Receive at most \a size bytes from file descriptor \a fd. If encryption is * available, decrypt the received buffer. * - * \return The number of bytes received on success. On receive errors, -E_RECV - * is returned. On crypt errors, the corresponding crypt error number is - * returned. + * \return The number of bytes received on success, negative on errors. * * \sa recv(2) */ @@ -254,8 +252,7 @@ int recv_buffer(int fd, char *buf, size_t size) { int n; - if (!size) - return -E_RECV; + assert(size); n = recv_bin_buffer(fd, buf, size - 1); if (n >= 0) buf[n] = '\0';