瀏覽代碼

change socket_write() return code semantics

instead of returning a write()-like result, return only a binary status
code - write errors are handled internally anyway, so user code doesn't
have to check the write length.
Oswald Buddenhagen 14 年之前
父節點
當前提交
8a72d204c9
共有 2 個文件被更改,包括 7 次插入6 次删除
  1. 5 5
      src/drv_imap.c
  2. 2 1
      src/socket.c

+ 5 - 5
src/drv_imap.c

@@ -244,11 +244,11 @@ v_submit_imap_cmd( imap_store_t *ctx, struct imap_cmd *cmd,
 		else
 			printf( ">>> %d LOGIN <user> <pass>\n", cmd->tag );
 	}
-	if (socket_write( &ctx->conn, buf, bufl ) != bufl)
+	if (socket_write( &ctx->conn, buf, bufl ) < 0)
 		goto bail;
 	if (litplus) {
-		if (socket_write( &ctx->conn, cmd->param.data, cmd->param.data_len ) != cmd->param.data_len ||
-		    socket_write( &ctx->conn, "\r\n", 2 ) != 2)
+		if (socket_write( &ctx->conn, cmd->param.data, cmd->param.data_len ) < 0 ||
+		    socket_write( &ctx->conn, "\r\n", 2 ) < 0)
 			goto bail;
 		free( cmd->param.data );
 		cmd->param.data = 0;
@@ -842,7 +842,7 @@ get_cmd_result( imap_store_t *ctx, struct imap_cmd *tcmd )
 				n = socket_write( &ctx->conn, cmdp->param.data, cmdp->param.data_len );
 				free( cmdp->param.data );
 				cmdp->param.data = 0;
-				if (n != (int)cmdp->param.data_len)
+				if (n < 0)
 					break;
 			} else if (cmdp->param.cont) {
 				if (cmdp->param.cont( ctx, cmdp, cmd ))
@@ -851,7 +851,7 @@ get_cmd_result( imap_store_t *ctx, struct imap_cmd *tcmd )
 				error( "IMAP error: unexpected command continuation request\n" );
 				break;
 			}
-			if (socket_write( &ctx->conn, "\r\n", 2 ) != 2)
+			if (socket_write( &ctx->conn, "\r\n", 2 ) < 0)
 				break;
 			if (!cmdp->param.cont)
 				ctx->literal_pending = 0;

+ 2 - 1
src/socket.c

@@ -387,8 +387,9 @@ socket_write( conn_t *sock, char *buf, int len )
 		socket_perror( "write", sock, n );
 		close( sock->fd );
 		sock->fd = -1;
+		return -1;
 	}
-	return n;
+	return 0;
 }
 
 int