summaryrefslogtreecommitdiff
path: root/cpp/src/qpid/sys
diff options
context:
space:
mode:
authorGordon Sim <gsim@apache.org>2008-04-29 20:15:18 +0000
committerGordon Sim <gsim@apache.org>2008-04-29 20:15:18 +0000
commitacc0dee435e1fa22e3b1e7cdfecf6913bf88988e (patch)
tree729f7a03543acf23380e68897f8788a3e6b45e2e /cpp/src/qpid/sys
parenta19ce3b1863f80c1232ec2690cd920325a39d71a (diff)
downloadqpid-python-acc0dee435e1fa22e3b1e7cdfecf6913bf88988e.tar.gz
QPID-974: allow the size of the queue of outgoing frames to be restricted
QPID-544: tidy up configuration (ensuring desired settings are used correctly, allowing tcp socket options to be set etc) git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid@652083 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'cpp/src/qpid/sys')
-rw-r--r--cpp/src/qpid/sys/Socket.h10
-rw-r--r--cpp/src/qpid/sys/posix/Socket.cpp33
2 files changed, 28 insertions, 15 deletions
diff --git a/cpp/src/qpid/sys/Socket.h b/cpp/src/qpid/sys/Socket.h
index cab95654ad..20dc0f1ce3 100644
--- a/cpp/src/qpid/sys/Socket.h
+++ b/cpp/src/qpid/sys/Socket.h
@@ -103,8 +103,16 @@ public:
int read(void *buf, size_t count) const;
int write(const void *buf, size_t count) const;
+ struct Configuration
+ {
+ virtual void configurePosixTcpSocket(int fd) const = 0;
+ virtual ~Configuration() {}
+ };
+
+ void configure(const Configuration&);
+
private:
- Socket(IOHandlePrivate*);
+ Socket(IOHandlePrivate*);
};
}}
diff --git a/cpp/src/qpid/sys/posix/Socket.cpp b/cpp/src/qpid/sys/posix/Socket.cpp
index 99cf7210b6..5f10cd84c2 100644
--- a/cpp/src/qpid/sys/posix/Socket.cpp
+++ b/cpp/src/qpid/sys/posix/Socket.cpp
@@ -104,8 +104,8 @@ Socket::Socket(IOHandlePrivate* h) :
void Socket::createTcp() const
{
- int& socket = impl->fd;
- if (socket != -1) Socket::close();
+ int& socket = impl->fd;
+ if (socket != -1) Socket::close();
int s = ::socket (PF_INET, SOCK_STREAM, 0);
if (s < 0) throw QPID_POSIX_ERROR(errno);
socket = s;
@@ -113,7 +113,7 @@ void Socket::createTcp() const
void Socket::setTimeout(const Duration& interval) const
{
- const int& socket = impl->fd;
+ const int& socket = impl->fd;
struct timeval tv;
toTimeval(tv, interval);
setsockopt(socket, SOL_SOCKET, SO_SNDTIMEO, &tv, sizeof(tv));
@@ -138,7 +138,7 @@ const char* h_errstr(int e) {
void Socket::connect(const std::string& host, int port) const
{
- const int& socket = impl->fd;
+ const int& socket = impl->fd;
struct sockaddr_in name;
name.sin_family = AF_INET;
name.sin_port = htons(port);
@@ -155,7 +155,7 @@ void Socket::connect(const std::string& host, int port) const
void
Socket::close() const
{
- int& socket = impl->fd;
+ int& socket = impl->fd;
if (socket == -1) return;
if (::close(socket) < 0) throw QPID_POSIX_ERROR(errno);
socket = -1;
@@ -164,7 +164,7 @@ Socket::close() const
ssize_t
Socket::send(const void* data, size_t size) const
{
- const int& socket = impl->fd;
+ const int& socket = impl->fd;
ssize_t sent = ::send(socket, data, size, 0);
if (sent < 0) {
if (errno == ECONNRESET) return SOCKET_EOF;
@@ -177,7 +177,7 @@ Socket::send(const void* data, size_t size) const
ssize_t
Socket::recv(void* data, size_t size) const
{
- const int& socket = impl->fd;
+ const int& socket = impl->fd;
ssize_t received = ::recv(socket, data, size, 0);
if (received < 0) {
if (errno == ETIMEDOUT) return SOCKET_TIMEOUT;
@@ -209,22 +209,22 @@ int Socket::listen(int port, int backlog) const
Socket* Socket::accept(struct sockaddr *addr, socklen_t *addrlen) const
{
- int afd = ::accept(impl->fd, addr, addrlen);
- if ( afd >= 0)
- return new Socket(new IOHandlePrivate(afd));
- else if (errno == EAGAIN)
- return 0;
+ int afd = ::accept(impl->fd, addr, addrlen);
+ if ( afd >= 0)
+ return new Socket(new IOHandlePrivate(afd));
+ else if (errno == EAGAIN)
+ return 0;
else throw QPID_POSIX_ERROR(errno);
}
int Socket::read(void *buf, size_t count) const
{
- return ::read(impl->fd, buf, count);
+ return ::read(impl->fd, buf, count);
}
int Socket::write(const void *buf, size_t count) const
{
- return ::write(impl->fd, buf, count);
+ return ::write(impl->fd, buf, count);
}
std::string Socket::getSockname() const
@@ -257,4 +257,9 @@ uint16_t Socket::getRemotePort() const
return atoi(getService(impl->fd, true).c_str());
}
+void Socket::configure(const Configuration& c)
+{
+ c.configurePosixTcpSocket(impl->fd);
+}
+
}} // namespace qpid::sys