@@ -20,23 +20,24 @@ int client_trigger_event(struct connection *client, struct mbuf *buf)
2020 return CORVUS_OK ;
2121}
2222
23- int client_read (struct connection * client , int read_socket )
23+ int client_read (struct connection * client )
2424{
2525 struct command * cmd ;
2626 struct mbuf * buf ;
2727 int status = CORVUS_OK , limit = 16 ;
2828
29- if (!STAILQ_EMPTY (& client -> info -> cmd_queue )
30- && STAILQ_FIRST (& client -> info -> cmd_queue )-> parse_done )
31- {
32- event_reregister (& client -> ctx -> loop , client , E_WRITABLE );
33- return CORVUS_OK ;
29+ cmd = STAILQ_FIRST (& client -> info -> cmd_queue );
30+ if (cmd != NULL && cmd -> parse_done ) {
31+ int size = socket_sndbuf_size (client -> fd );
32+ LOG (DEBUG , "%p %d %d" , cmd , client -> info -> sndbuf , size );
33+ if (size >= 0 && client -> info -> sndbuf > size ) {
34+ return CORVUS_OK ;
35+ }
3436 }
3537
3638 do {
3739 buf = conn_get_buf (client );
3840 if (mbuf_read_size (buf ) <= 0 ) {
39- if (!read_socket ) break ;
4041 buf = conn_get_buf (client );
4142 status = conn_read (client , buf );
4243 if (status != CORVUS_OK ) return status ;
@@ -89,6 +90,10 @@ int client_write(struct connection *client)
8990 }
9091
9192 if (info -> iov .len <= 0 ) {
93+ if (!STAILQ_EMPTY (& info -> cmd_queue ) && conn_register (client ) == CORVUS_ERR ) {
94+ LOG (ERROR , "client_write: fail to reregister client %d" , client -> fd );
95+ return CORVUS_ERR ;
96+ }
9297 cmd_iov_reset (& info -> iov );
9398 return CORVUS_OK ;
9499 }
@@ -102,7 +107,7 @@ int client_write(struct connection *client)
102107 if (status == CORVUS_AGAIN ) return CORVUS_OK ;
103108
104109 if (info -> iov .cursor >= info -> iov .len ) {
105- cmd_iov_reset (& info -> iov );
110+ cmd_iov_free (& info -> iov );
106111 if (event_reregister (& ctx -> loop , client , E_READABLE ) == CORVUS_ERR ) {
107112 LOG (ERROR , "client_write: fail to reregister client %d" , client -> fd );
108113 return CORVUS_ERR ;
@@ -112,7 +117,7 @@ int client_write(struct connection *client)
112117 client -> fd , client -> ev -> fd );
113118 return CORVUS_ERR ;
114119 }
115- } else if (event_reregister ( & ctx -> loop , client , E_WRITABLE ) == CORVUS_ERR ) {
120+ } else if (conn_register ( client ) == CORVUS_ERR ) {
116121 LOG (ERROR , "client_write: fail to reregister client %d" , client -> fd );
117122 return CORVUS_ERR ;
118123 }
@@ -147,7 +152,7 @@ void client_ready(struct connection *self, uint32_t mask)
147152 if (mask & E_READABLE ) {
148153 LOG (DEBUG , "client readable" );
149154
150- int status = client_read (self , 1 );
155+ int status = client_read (self );
151156 if (status == CORVUS_ERR || status == CORVUS_EOF ) {
152157 client_eof (self );
153158 return ;
@@ -178,7 +183,7 @@ void client_event_ready(struct connection *self, uint32_t mask)
178183 client -> info -> last_active = time (NULL );
179184
180185 if (mask & E_READABLE ) {
181- if (client_read (client , 0 ) == CORVUS_ERR ) {
186+ if (client_read (client ) == CORVUS_ERR ) {
182187 client_eof (client );
183188 return ;
184189 }
@@ -208,6 +213,12 @@ struct connection *client_create(struct context *ctx, int fd)
208213 return NULL ;
209214 }
210215
216+ client -> info -> sndbuf = socket_get_sndbuf (client -> fd );
217+ if (client -> info -> sndbuf == -1 ) {
218+ client -> info -> sndbuf = DEFAULT_SNDBUF ;
219+ }
220+ client -> info -> sndbuf >>= 1 ;
221+
211222 int evfd = socket_create_eventfd ();
212223 client -> ev = conn_create (ctx );
213224 if (evfd == -1 || client -> ev == NULL ) {
@@ -248,7 +259,7 @@ void client_eof(struct connection *client)
248259
249260 // don't care response any more
250261 cmd_iov_clear (client -> ctx , & client -> info -> iov );
251- cmd_iov_reset (& client -> info -> iov );
262+ cmd_iov_free (& client -> info -> iov );
252263
253264 // request may not write
254265 if (client -> info -> refcount <= 0 ) {
0 commit comments