diff options
| author | Alan Conway <aconway@apache.org> | 2006-11-13 19:28:23 +0000 |
|---|---|---|
| committer | Alan Conway <aconway@apache.org> | 2006-11-13 19:28:23 +0000 |
| commit | 922d1249a1a48c13a2e37f1efc1b3204ca5e9813 (patch) | |
| tree | 0a5284b22967b19a97d02284d3bafe2ae9d79df0 /cpp/src/qpid/posix | |
| parent | fc5ad32cc8f2d4d793c0cf79382755e9fca2357c (diff) | |
| download | qpid-python-922d1249a1a48c13a2e37f1efc1b3204ca5e9813.tar.gz | |
EventChannel classes, start of epoll-based posix implementation.
git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid@474452 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'cpp/src/qpid/posix')
| -rw-r--r-- | cpp/src/qpid/posix/EpollEventChannel.cpp | 74 | ||||
| -rw-r--r-- | cpp/src/qpid/posix/EpollEventChannel.h | 48 | ||||
| -rw-r--r-- | cpp/src/qpid/posix/Socket.cpp | 12 | ||||
| -rw-r--r-- | cpp/src/qpid/posix/check.cpp | 14 | ||||
| -rw-r--r-- | cpp/src/qpid/posix/check.h | 8 |
5 files changed, 141 insertions, 15 deletions
diff --git a/cpp/src/qpid/posix/EpollEventChannel.cpp b/cpp/src/qpid/posix/EpollEventChannel.cpp new file mode 100644 index 0000000000..1418507542 --- /dev/null +++ b/cpp/src/qpid/posix/EpollEventChannel.cpp @@ -0,0 +1,74 @@ +/* + * + * Copyright (c) 2006 The Apache Software Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include <qpid/sys/EventChannel.h> +#include <sys/epoll.h> +#include "EpollEventChannel.h" + +namespace qpid { +namespace sys { + +EventChannel::shared_ptr EventChannel::create() +{ + return EventChannel::shared_ptr(new EpollEventChannel()); +} + +EpollEventChannel::EpollEventChannel() +{ + // TODO aconway 2006-11-13: How to choose size parameter? + static const size_t estimatedFdsForEpoll = 1000; + epollFd = epoll_create(estimatedFdsForEpoll); +} + +void +EpollEventChannel::post(ReadEvent& /*event*/) +{ +} + +void +EpollEventChannel::post(WriteEvent& /*event*/) +{ +} + +void +EpollEventChannel::post(AcceptEvent& /*event*/) +{ +} + +void +EpollEventChannel::post(NotifyEvent& /*event*/) +{ +} + +inline void +EpollEventChannel::post(Event& /*event*/) +{ +} + +Event* +EpollEventChannel::getEvent() +{ + return 0; +} + +void +EpollEventChannel::dispose(void* /*buffer*/, size_t) +{ +} + +}} diff --git a/cpp/src/qpid/posix/EpollEventChannel.h b/cpp/src/qpid/posix/EpollEventChannel.h new file mode 100644 index 0000000000..8128d5276f --- /dev/null +++ b/cpp/src/qpid/posix/EpollEventChannel.h @@ -0,0 +1,48 @@ +/* + * + * Copyright (c) 2006 The Apache Software Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include <qpid/sys/EventChannel.h> + +namespace qpid { +namespace sys { + +/** Epoll-based implementation of the event channel */ +class EpollEventChannel : public EventChannel +{ + public: + + EpollEventChannel(); + ~EpollEventChannel(); + + virtual void post(ReadEvent& event); + virtual void post(WriteEvent& event); + virtual void post(AcceptEvent& event); + virtual void post(NotifyEvent& event); + + inline void post(Event& event); + + virtual Event* getEvent(); + + virtual void dispose(void* buffer, size_t size); + + private: + int epollFd; + +}; + +}} diff --git a/cpp/src/qpid/posix/Socket.cpp b/cpp/src/qpid/posix/Socket.cpp index 3101be54f4..1321ae6b0d 100644 --- a/cpp/src/qpid/posix/Socket.cpp +++ b/cpp/src/qpid/posix/Socket.cpp @@ -33,7 +33,7 @@ using namespace qpid::sys; Socket::Socket() : socket(::socket (PF_INET, SOCK_STREAM, 0)) { - if (socket == 0) CHECK(-1); + CHECKNN(socket == 0); } void @@ -53,16 +53,16 @@ Socket::connect(const std::string& host, int port) name.sin_family = AF_INET; name.sin_port = htons(port); struct hostent* hp = gethostbyname ( host.c_str() ); - if (hp == 0) CHECK(-1); // TODO aconway 2006-11-09: error message? + if (hp == 0) CHECK0(-1); // TODO aconway 2006-11-09: error message? memcpy(&name.sin_addr.s_addr, hp->h_addr_list[0], hp->h_length); - CHECK(::connect(socket, (struct sockaddr*)(&name), sizeof(name))); + CHECK0(::connect(socket, (struct sockaddr*)(&name), sizeof(name))); } void Socket::close() { if (socket == 0) return; - CHECK(::close(socket)); + CHECK0(::close(socket)); socket = 0; } @@ -73,7 +73,7 @@ Socket::send(const char* data, size_t size) if (sent < 0) { if (errno == ECONNRESET) return SOCKET_EOF; if (errno == ETIMEDOUT) return SOCKET_TIMEOUT; - CHECK(sent); + CHECK0(sent); } return sent; } @@ -84,7 +84,7 @@ Socket::recv(char* data, size_t size) ssize_t received = ::recv(socket, data, size, 0); if (received < 0) { if (errno == ETIMEDOUT) return SOCKET_TIMEOUT; - CHECK(received); + CHECK0(received); } return received; } diff --git a/cpp/src/qpid/posix/check.cpp b/cpp/src/qpid/posix/check.cpp index 5e8e9e7ca2..3470906639 100644 --- a/cpp/src/qpid/posix/check.cpp +++ b/cpp/src/qpid/posix/check.cpp @@ -22,10 +22,12 @@ #include <qpid/QpidError.h> #include "check.h" -void qpid::sys::check(long result, const char* file, const int line) { - if (result != 0) { - char buf[512]; - char* msg = strerror_r(errno, buf, sizeof(buf)); - throw QpidError(errno, msg, file, line); - } +namespace qpid { +namespace sys { + +std::string strError() { + char buf[512]; + return strerror_r(errno, buf, sizeof(buf)); } + +}} diff --git a/cpp/src/qpid/posix/check.h b/cpp/src/qpid/posix/check.h index d1de9360a4..666637b1c2 100644 --- a/cpp/src/qpid/posix/check.h +++ b/cpp/src/qpid/posix/check.h @@ -23,14 +23,16 @@ */ #include <errno.h> +#include <string> +#include <qpid/QpidError.h> namespace qpid { namespace sys { -void check(long result, const char* file, const int line); - -#define CHECK(N) qpid::sys::check(N, __FILE__, __LINE__) +std::string errnoToString(); +#define CHECK0(N) if ((N)!=0) THROW_QPID_ERROR(INTERNAL_ERROR, errnoToString()) +#define CHECKNN(N) if ((N)<0) THROW_QPID_ERROR(INTERNAL_ERROR, errnoToString()) }} |
