summaryrefslogtreecommitdiff
path: root/node/TcpSocket.cpp
diff options
context:
space:
mode:
authorAdam Ierymenko <adam.ierymenko@gmail.com>2014-03-27 18:23:02 -0700
committerAdam Ierymenko <adam.ierymenko@gmail.com>2014-03-27 18:23:02 -0700
commitb73c36acbf03431fd7fa3584e8621875fdcbebf4 (patch)
treea08a976e4d4a63efecc2892bc969cc60141b4c5f /node/TcpSocket.cpp
parent181369964f501c3c702971b30c82b9e84eed58db (diff)
parentd2c5d7150253a5ae5613cac1d65e84b3aa5d33bc (diff)
downloadinfinitytier-b73c36acbf03431fd7fa3584e8621875fdcbebf4.tar.gz
infinitytier-b73c36acbf03431fd7fa3584e8621875fdcbebf4.zip
Merge branch 'adamierymenko-dev' of ssh://shub-niggurath.zerotier.com:222/git/ZeroTierOne into adamierymenko-dev
Diffstat (limited to 'node/TcpSocket.cpp')
-rw-r--r--node/TcpSocket.cpp34
1 files changed, 12 insertions, 22 deletions
diff --git a/node/TcpSocket.cpp b/node/TcpSocket.cpp
index a422dec6..5d475c93 100644
--- a/node/TcpSocket.cpp
+++ b/node/TcpSocket.cpp
@@ -73,7 +73,7 @@ bool TcpSocket::send(const InetAddress &to,const void *msg,unsigned int msglen)
Mutex::Lock _l(_writeLock);
- bool outputWasEnqueued = (_outptr != 0);
+ bool writeInProgress = ((_outptr != 0)||(_connecting));
// Ensure that _outbuf is large enough
unsigned int newptr = _outptr + 5 + msglen;
@@ -102,7 +102,7 @@ bool TcpSocket::send(const InetAddress &to,const void *msg,unsigned int msglen)
for(unsigned int i=0;i<msglen;++i)
_outbuf[_outptr++] = ((const unsigned char *)msg)[i];
- if (!outputWasEnqueued) {
+ if (!writeInProgress) {
// If no output was enqueued before this, try to send() it and then
// start a queued write if any remains after that.
@@ -164,32 +164,22 @@ bool TcpSocket::notifyAvailableForWrite(const SharedPtr<Socket> &self,SocketMana
if (_outptr) {
int n = (int)::send(_sock,(const char *)_outbuf,_outptr,0);
- if (n < 0) {
+ if (n <= 0) {
switch(errno) {
-#ifdef EBADF
- case EBADF:
+#ifdef EAGAIN
+ case EAGAIN:
#endif
-#ifdef EINVAL
- case EINVAL:
+#if defined(EWOULDBLOCK) && ( !defined(EAGAIN) || (EWOULDBLOCK != EAGAIN) )
+ case EWOULDBLOCK:
#endif
-#ifdef ENOTSOCK
- case ENOTSOCK:
+#ifdef EINTR
+ case EINTR:
#endif
-#ifdef ECONNRESET
- case ECONNRESET:
-#endif
-#ifdef EPIPE
- case EPIPE:
-#endif
-#ifdef ENETDOWN
- case ENETDOWN:
-#endif
- return false;
- default:
break;
+ default:
+ return false;
}
- } else if (n > 0)
- memmove(_outbuf,_outbuf + (unsigned int)n,_outptr -= (unsigned int)n);
+ } else memmove(_outbuf,_outbuf + (unsigned int)n,_outptr -= (unsigned int)n);
}
if (!_outptr)