summaryrefslogtreecommitdiff
path: root/cpp/src/qpid/sys/posix/Socket.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'cpp/src/qpid/sys/posix/Socket.cpp')
-rw-r--r--cpp/src/qpid/sys/posix/Socket.cpp31
1 files changed, 19 insertions, 12 deletions
diff --git a/cpp/src/qpid/sys/posix/Socket.cpp b/cpp/src/qpid/sys/posix/Socket.cpp
index 840d9d4b2a..7b906f33e8 100644
--- a/cpp/src/qpid/sys/posix/Socket.cpp
+++ b/cpp/src/qpid/sys/posix/Socket.cpp
@@ -98,12 +98,14 @@ std::string getService(int fd, bool local)
Socket::Socket() :
IOHandle(new IOHandlePrivate),
- nonblocking(false)
+ nonblocking(false),
+ nodelay(false)
{}
Socket::Socket(IOHandlePrivate* h) :
IOHandle(h),
- nonblocking(false)
+ nonblocking(false),
+ nodelay(false)
{}
void Socket::createSocket(const SocketAddress& sa) const
@@ -116,6 +118,7 @@ void Socket::createSocket(const SocketAddress& sa) const
try {
if (nonblocking) setNonblocking();
+ if (nodelay) setTcpNoDelay();
} catch (std::exception&) {
::close(s);
socket = -1;
@@ -134,8 +137,21 @@ void Socket::setTimeout(const Duration& interval) const
void Socket::setNonblocking() const {
int& socket = impl->fd;
- if (socket != -1) QPID_POSIX_CHECK(::fcntl(socket, F_SETFL, O_NONBLOCK));
nonblocking = true;
+ if (socket != -1) {
+ QPID_POSIX_CHECK(::fcntl(socket, F_SETFL, O_NONBLOCK));
+ }
+}
+
+void Socket::setTcpNoDelay() const
+{
+ int& socket = impl->fd;
+ nodelay = true;
+ if (socket != -1) {
+ int flag = 1;
+ int result = setsockopt(impl->fd, IPPROTO_TCP, TCP_NODELAY, (char *)&flag, sizeof(flag));
+ QPID_POSIX_CHECK(result);
+ }
}
void Socket::connect(const std::string& host, uint16_t port) const
@@ -258,13 +274,4 @@ int Socket::getError() const
return result;
}
-void Socket::setTcpNoDelay(bool nodelay) const
-{
- if (nodelay) {
- int flag = 1;
- int result = setsockopt(impl->fd, IPPROTO_TCP, TCP_NODELAY, (char *)&flag, sizeof(flag));
- QPID_POSIX_CHECK(result);
- }
-}
-
}} // namespace qpid::sys