how redis ensure all request data can be readed into buffer by only one 'read' function call? -


i read redis source code recently, , i'm studying networking codes.

redis use nonblock mode , epoll(or simliar) networking data read/write. when read data event arrived,"readqueryfromclient" function called, , in function request data readed buffer.

in "readqueryfromclient" function, if there data arrived, data readed buffer through 1 'read' function, , request handled.

 nread = read(fd, c->querybuf+qblen, readlen); // **one read function** //... other codes check read function retuen value processinputbuffer(c);// **request handled in function** 

my question is: how redis ensure request data can readed buffer 1 'read' function call, maybe data gotten more 'read' function call?

processinputbuffer(c);// request handled in function

that part not true. redis protocol designed include length of every chunk of data passed around. server knows how data has read make complete request out of it. inside processinputbuffer if neither processinlinebuffer nor processmultibulkbuffer returns redis_ok (i.e. request terminator not found in buffer/not enough arguments), control falls out of function. processinputbuffer did in case filling chunk of client buffer , updating parsing state. then, on next iteration of event loop, in call aeprocessevents, if there unread data remaining in socket buffer, readqueryfromclient callback triggered again parse remaining data.


Comments

Popular posts from this blog

ios - UICollectionView Self Sizing Cells with Auto Layout -

node.js - ldapjs - write after end error -

DOM Manipulation in Wordpress (and elsewhere) using php -