[sheepdog] [PATCH v2 5/7] net: refactor client_rx_handler()
Liu Yuan
namei.unix at gmail.com
Thu Jul 19 04:02:43 CEST 2012
From: Liu Yuan <tailai.ly at taobao.com>
Signed-off-by: Liu Yuan <tailai.ly at taobao.com>
---
sheep/sdnet.c | 32 ++++++++++++++++++++++++--------
1 file changed, 24 insertions(+), 8 deletions(-)
diff --git a/sheep/sdnet.c b/sheep/sdnet.c
index ea48453..c9063ed 100644
--- a/sheep/sdnet.c
+++ b/sheep/sdnet.c
@@ -508,7 +508,7 @@ static void init_rx_hdr(struct client_info *ci)
ci->conn.rx_buf = &ci->conn.rx_hdr;
}
-static void client_rx_handler(struct client_info *ci)
+static inline int begin_rx(struct client_info *ci)
{
int ret;
uint64_t data_len;
@@ -549,14 +549,23 @@ static void client_rx_handler(struct client_info *ci)
eprintf("bug: unknown state %d\n", conn->c_rx_state);
}
- if (is_conn_dead(conn))
- return clear_client_info(ci);
+ if (is_conn_dead(conn)) {
+ clear_client_info(ci);
+ return -1;
+ }
/* Short read happens */
if (conn->c_rx_state != C_IO_END)
- return;
+ return -1;
+
+ return 0;
+}
+
+static inline void finish_rx(struct client_info *ci)
+{
+ struct request *req;
+ struct sd_req *hdr = &ci->conn.rx_hdr;
- /* now we have a complete command */
req = ci->rx_req;
init_rx_hdr(ci);
if (hdr->flags & SD_FLAG_CMD_WRITE)
@@ -564,11 +573,18 @@ static void client_rx_handler(struct client_info *ci)
else
req->rp.data_length = hdr->data_length;
- dprintf("connection from: %d, %s:%d\n", ci->conn.fd,
- ci->conn.ipstr, ci->conn.port);
+ dprintf("%d, %s:%d\n", ci->conn.fd, ci->conn.ipstr, ci->conn.port);
queue_request(req);
}
+static void do_client_rx(struct client_info *ci)
+{
+ if (begin_rx(ci) < 0)
+ return;
+
+ finish_rx(ci);
+}
+
static void init_tx_hdr(struct client_info *ci)
{
struct sd_rsp *rsp = (struct sd_rsp *)&ci->conn.tx_hdr;
@@ -743,7 +759,7 @@ static void client_handler(int fd, int events, void *data)
return clear_client_info(ci);
if (events & EPOLLIN)
- client_rx_handler(ci);
+ do_client_rx(ci);
if (events & EPOLLOUT)
client_tx_handler(ci);
--
1.7.10.2
More information about the sheepdog
mailing list