Skip to content
Browse files

implement kqueue io_service

  • Loading branch information...
1 parent b75878a commit e1df706caecf9ba80bd23cdd2b1e4d5a15c6b27c yayanyang committed Sep 23, 2012
Showing with 72 additions and 12 deletions.
  1. +5 −1 io/abi.cpp
  2. +1 −0 io/configure.h.in
  3. +3 −1 io/io_service_reactor.cpp
  4. +7 −5 io/io_service_reactor.hpp
  5. +2 −1 io/object.hpp
  6. +6 −0 io/socket.cpp
  7. +1 −0 io/socket.hpp
  8. +18 −0 io/socket_reactor.cpp
  9. +18 −0 io/socket_reactor.hpp
  10. +3 −1 io/unix.cmake
  11. +1 −0 sys/abi.h
  12. +7 −3 trace/message.cpp
View
6 io/abi.cpp
@@ -5,6 +5,8 @@
#include <lemon/io/io_service_reactor.hpp>
#endif //
+#ifdef LEMON_NULL
+
using namespace lemon;
using namespace lemon::io;
@@ -477,4 +479,6 @@ LEMON_IO_API
{
*errorCode = e;
}
-}
+}
+
+#endif
View
1 io/configure.h.in
@@ -1,4 +1,5 @@
#cmakedefine LEMON_IO_IOCP
#cmakedefine LEMON_IO_EPOLL
+#cmakedefine LEMON_IO_KQUEUE
View
4 io/io_service_reactor.cpp
@@ -4,6 +4,8 @@
namespace lemon{namespace io{namespace core{
+ io_data::io_data(size_t type):_type(type) {}
+
io_data::io_data(size_t type,void * userdata, LemonIOCallback callback, void * buffer, size_t bufferSize)
:_type(type),_userdata(userdata),_callback(callback),_buffer(buffer),_bufferSize(bufferSize)
{
@@ -161,4 +163,4 @@ namespace lemon{namespace io{namespace core{
}
}}}
-#endif //
+#endif //
View
12 io/io_service_reactor.hpp
@@ -30,7 +30,7 @@ namespace lemon{namespace io{namespace core{
{
public:
- io_data(size_t type):_type(type) {}
+ io_data(size_t type);
io_data(size_t type,void * userdata, LemonIOCallback callback, void * buffer, size_t bufferSize);
@@ -113,10 +113,6 @@ namespace lemon{namespace io{namespace core{
typedef memory::fixed::allocator<sizeof(accept_io_data)> accept_io_data_allocator;
typedef memory::ringbuffer::allocator<sizeof(io_data*)> complete_queue;
-
- io_service_reactor();
-
- ~io_service_reactor();
void reset() {_exit = false; }
@@ -126,6 +122,12 @@ namespace lemon{namespace io{namespace core{
void post_one(LemonIOCallback callback,void * userdata,void * buffer, size_t bufferSize,LemonErrorInfo *errorCode);
+ protected:
+
+ io_service_reactor();
+
+ ~io_service_reactor();
+
public:
io_data * alloc_io_data(size_t type,void * userdata, LemonIOCallback callback, void * buffer, size_t bufferSize);
View
3 io/object.hpp
@@ -8,6 +8,7 @@
*/
#ifndef LEMON_IO_OBJECT_HPP
#define LEMON_IO_OBJECT_HPP
+#include <cstddef>
#include <lemon/io/abi.h>
#include <lemonxx/sys/sys.hpp>
#include <lemonxx/utility/utility.hpp>
@@ -22,7 +23,7 @@ namespace lemon{namespace io{namespace core{
io_object(io_service * service):_ioService(service) {}
- io_object(){}
+ virtual ~io_object(){}
public:
View
6 io/socket.cpp
@@ -1,9 +1,15 @@
#include <lemon/io/socket.hpp>
#ifdef LEMON_IO_IOCP
#include <lemon/io/io_service_iocp.hpp>
+#elif defined(LEMON_IO_KQUEUE)
+#include <lemon/io/io_service_kqueue.hpp>
#else
#endif //LEMON_IO_IOCP
+#ifndef WIN32
+#include <unistd.h>
+#endif //WIN32
+
namespace lemon{namespace io{namespace core{
View
1 io/socket.hpp
@@ -12,6 +12,7 @@
#ifndef WIN32
#define SOCKET_ERROR -1
+#define INVALID_SOCKET -1
#define LEMON_SOCKET_ERROR(errorCode) LEMON_POSIX_ERROR(errorCode,errno)
#else
#define LEMON_SOCKET_ERROR(errorCode) LEMON_WIN32_ERROR(errorCode,WSAGetLastError())
View
18 io/socket_reactor.cpp
@@ -0,0 +1,18 @@
+#include <lemon/io/socket_reactor.hpp>
+
+namespace lemon{namespace io{namespace core{
+
+ socket::socket(int af, int type, int protocol,io_service * service)
+ :socket_base(af,type,protocol,::socket(af,type,protocol),service)
+ {
+
+ }
+
+ socket::socket(int af, int type, int protocol,LemonNativeSock sock, io_service * service)
+ :socket_base(af,type,protocol,sock,service)
+ {
+
+ }
+
+
+}}}
View
18 io/socket_reactor.hpp
@@ -9,6 +9,24 @@
#ifndef LEMON_IO_SOCKET_REACTOR_HPP
#define LEMON_IO_SOCKET_REACTOR_HPP
+#include <lemon/io/socket.hpp>
+#ifndef LEMON_IO_IOCP
+
+
+namespace lemon{namespace io{namespace core{
+
+ class socket : public socket_base
+ {
+ public:
+
+ socket(int af, int type, int protocol,io_service * service);
+
+ socket(int af, int type, int protocol,LemonNativeSock sock, io_service * service);
+ };
+
+}}}
+
+#endif //
#endif //LEMON_IO_SOCKET_REACTOR_HPP
View
4 io/unix.cmake
@@ -11,4 +11,6 @@ if(LEMON_IO_EPOLL)
lemon_project_link_libs(aio)
-endif()
+endif()
+
+check_include_files(sys/event.h LEMON_IO_KQUEUE)
View
1 sys/abi.h
@@ -10,6 +10,7 @@
#define LEMON_SYS_ABI_H
#include <stdio.h>
#include <wchar.h>
+#include <stdlib.h>
#include <lemon/sys/stdtypes.h>
#include <lemon/sys/configure.h>
#include <lemon/sys/endianess.h>
View
10 trace/message.cpp
@@ -148,7 +148,9 @@ namespace lemon{namespace trace{
result += writer.write((const byte_t*)&pid,sizeof(pid));
- lemon_tid_t tid = htonl(_threadId);
+ uint32_t tid = *(uint32_t*)&_threadId;
+
+ tid = htonl(tid);
result += writer.write((const byte_t*)&tid,sizeof(tid));
@@ -173,7 +175,7 @@ namespace lemon{namespace trace{
{
lemon_pid_t pid;
- lemon_tid_t tid;
+ uint32_t tid;
lemon_trace_flag flag;
@@ -187,7 +189,9 @@ namespace lemon{namespace trace{
result += reader.read((byte_t*)&tid,sizeof(tid));
- _threadId = ntohl(tid);
+ tid = ntohl(tid);
+
+ _threadId = *(lemon_tid_t*)&tid;
result += reader.read((byte_t*)&flag,sizeof(flag));

0 comments on commit e1df706

Please sign in to comment.
Something went wrong with that request. Please try again.