- nread = read(c->fd,buf,sizeof(buf));
- if (nread == -1) {
- fprintf(stderr, "Reading from socket: %s\n", strerror(errno));
- freeClient(c);
- return;
- }
- if (nread == 0) {
- fprintf(stderr, "EOF from client\n");
- freeClient(c);
- return;
- }
- c->totreceived += nread;
- c->ibuf = sdscatlen(c->ibuf,buf,nread);
- len = sdslen(c->ibuf);
-
- if (c->replytype == REPLY_INT ||
- c->replytype == REPLY_RETCODE)
- {
- /* Check if the first line is complete. This is everything we need
- * when waiting for an integer or status code reply.*/
- if ((p = strstr(c->ibuf,"\r\n")) != NULL)
- goto done;
- } else if (c->replytype == REPLY_BULK) {
- int advance = 0;
- if (c->readlen < 0) {
- advance = readLen(c->ibuf+pos,&c->readlen);
- if (advance) {
- pos += advance;
- if (c->readlen == -1) {
- goto done;
- } else {
- /* include the trailing \r\n */
- c->readlen += 2;
- }
- } else {
- goto skip;
- }
- }
+ /* Calculate latency only for the first read event. This means that the
+ * server already sent the reply and we need to parse it. Parsing overhead
+ * is not part of the latency, so calculate it only once, here. */
+ if (c->latency < 0) c->latency = ustime()-(c->start);