From: Michal B. <mic...@ge...> - 2011-02-28 11:58:15
|
Hi! No, this is not an error, the code is good. The “tcptoread” function reads exactly “leng” bytes but it cannot wait for data longer than “msecto” milliseconds. The function returns number of bytes read. Appearance of EOF while reading is equivalent to an error. If we want to read 8 bytes and receive just 6 and the connection got broken it is not important for me if it is 6, 4 or 0 – it is important it’s less than 8. In other places in the code values returned by this function are compared to the length passed as a parameter and whenever value received is different, it is treated as an error. So to be honest the change you proposed doesn’t change anything. I hope the explanation is quite clear.) Thank you Kind regards Michał Borychowski MooseFS Support Manager _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ Gemius S.A. ul. Wołoska 7, 02-672 Warszawa Budynek MARS, klatka D Tel.: +4822 874-41-00 Fax : +4822 874-41-01 From: Lin Yang [mailto:id...@gm...] Sent: Saturday, February 19, 2011 6:25 PM To: moo...@li... Subject: [Moosefs-users] A bug in mfs in mfscommon/sockets.c : line 381 int32_t tcptoread(int sock,void *buff,uint32_t leng,uint32_t msecto) { uint32_t rcvd=0; int i; struct pollfd pfd; pfd.fd = sock; pfd.events = POLLIN; while (rcvd<leng) { pfd.revents = 0; if (poll(&pfd,1,msecto)<0) { return -1; } if (pfd.revents & POLLIN) { i = read(sock,((uint8_t*)buff)+rcvd,leng-rcvd); if (i<=0) { //this code work only in Long Connection without EOF return i; } rcvd+=i; } else { errno = ETIMEDOUT; return -1; } } return rcvd; } ------------------------------------------------- should be replaced with : if (i==0) { //EOF return rcvd; } if (i<0) { return i; } -- 杨林 中科院计算技术研究所 15811038200 id...@gm... http://idning.javaeye.com/ |