Permalink
Browse files

implement iocp

Signed-off-by: yayanyang <yayanyang@gmail.com>
  • Loading branch information...
1 parent b9b296c commit 9810ef440725df9afa05dcebc79a14719dbcdfb2 yayanyang committed Sep 1, 2012
Showing with 274 additions and 24 deletions.
  1. +99 −3 io/abi.cpp
  2. +54 −2 io/abi.h
  3. +1 −1 io/iocp/io_service.cpp
  4. +10 −7 io/iocp/io_service.hpp
  5. +86 −7 io/iocp/socket.cpp
  6. +23 −3 io/iocp/socket.hpp
  7. +1 −1 sys/win32.cpp
View
@@ -364,26 +364,122 @@ LEMON_IO_API
catch(const error_info & e)
{
*errorCode = e;
+
+ return LEMON_HANDLE_NULL_VALUE;
}
}
LEMON_IO_API
void
LemonAsyncAccept(
__lemon_in LemonIO socket,
- __lemon_in LemonIO peer,
__lemon_inout struct sockaddr * addr,
__lemon_inout socklen_t * addrlen,
- __lemon_in LemonIOCallback callback,
+ __lemon_in LemonAcceptCallback callback,
__lemon_in void * userData,
__lemon_inout LemonErrorInfo *errorCode)
{
try
{
- reinterpret_cast<Socket*>(socket)->Accept(reinterpret_cast<Socket*>(peer),addr,addrlen,callback,userData);
+ reinterpret_cast<Socket*>(socket)->Accept(addr,addrlen,callback,userData);
}
catch(const error_info & e)
{
*errorCode = e;
}
}
+
+
+LEMON_IO_API
+ size_t
+ LemonSendTo(
+ __lemon_in LemonIO socket,
+ __lemon_in const lemon_byte_t * buffer __lemon_buffer(bufferSize),
+ __lemon_in size_t bufferSize,
+ __lemon_in int flags,
+ __lemon_in const struct sockaddr * address,
+ __lemon_in socklen_t addressSize,
+ __lemon_inout LemonErrorInfo *errorCode)
+{
+ try
+ {
+ return reinterpret_cast<Socket*>(socket)->SendTo(buffer,bufferSize,flags,address,addressSize);
+ }
+ catch(const error_info & e)
+ {
+ *errorCode = e;
+
+ return size_t(-1);
+ }
+}
+
+
+LEMON_IO_API
+ void
+ LemonAsyncSendTo(
+ __lemon_in LemonIO socket,
+ __lemon_in const lemon_byte_t * buffer __lemon_buffer(bufferSize),
+ __lemon_in size_t bufferSize,
+ __lemon_in int flags,
+ __lemon_in const struct sockaddr * address,
+ __lemon_in socklen_t addressSize,
+ __lemon_in LemonIOCallback callback,
+ __lemon_in void *userData,
+ __lemon_inout LemonErrorInfo *errorCode)
+{
+ try
+ {
+ reinterpret_cast<Socket*>(socket)->SendTo(buffer,bufferSize,flags,address,addressSize,callback ,userData);
+ }
+ catch(const error_info & e)
+ {
+ *errorCode = e;
+ }
+}
+
+LEMON_IO_API
+ size_t
+ LemonReceiveFrom(
+ __lemon_in LemonIO socket,
+ __lemon_in lemon_byte_t * buffer __lemon_buffer(bufferSize),
+ __lemon_in size_t bufferSize,
+ __lemon_in int flags,
+ __lemon_in struct sockaddr * address,
+ __lemon_in socklen_t *addressSize,
+ __lemon_inout LemonErrorInfo *errorCode)
+{
+ try
+ {
+ return reinterpret_cast<Socket*>(socket)->RecieveFrom(buffer,bufferSize,flags,address,addressSize);
+ }
+ catch(const error_info & e)
+ {
+ *errorCode = e;
+
+ return size_t(-1);
+ }
+}
+
+
+LEMON_IO_API
+ void
+ LemonAsyncReceiveFrom(
+ __lemon_in LemonIO socket,
+ __lemon_in lemon_byte_t * buffer __lemon_buffer(bufferSize),
+ __lemon_in size_t bufferSize,
+ __lemon_in int flags,
+ __lemon_in struct sockaddr * address,
+ __lemon_in socklen_t *addressSize,
+ __lemon_in LemonIOCallback callback,
+ __lemon_in void *userData,
+ __lemon_inout LemonErrorInfo *errorCode)
+{
+ try
+ {
+ reinterpret_cast<Socket*>(socket)->RecieveFrom(buffer,bufferSize,flags,address,addressSize,callback ,userData);
+ }
+ catch(const error_info & e)
+ {
+ *errorCode = e;
+ }
+}
View
@@ -111,6 +111,8 @@ LEMON_IO_API
#define SD_RECEIVE SHUT_RD
#endif //SD_BOTH
+typedef void (*LemonAcceptCallback)(void * userdata , LemonIO io , size_t numberOfBytesTransferred , const LemonErrorInfo *errorCode);
+
LEMON_IO_API
LemonIO
LemonSock(
@@ -219,11 +221,61 @@ LEMON_IO_API
void
LemonAsyncAccept(
__lemon_in LemonIO socket,
- __lemon_in LemonIO peer,
__lemon_inout struct sockaddr * addr,
__lemon_inout socklen_t * addrlen,
- __lemon_in LemonIOCallback callback,
+ __lemon_in LemonAcceptCallback callback,
__lemon_in void * userData,
__lemon_inout LemonErrorInfo *errorCode);
+
+LEMON_IO_API
+ size_t
+ LemonSendTo(
+ __lemon_in LemonIO socket,
+ __lemon_in const lemon_byte_t * buffer __lemon_buffer(bufferSize),
+ __lemon_in size_t bufferSize,
+ __lemon_in int flags,
+ __lemon_in const struct sockaddr * address,
+ __lemon_in socklen_t addressSize,
+ __lemon_inout LemonErrorInfo *errorCode);
+
+
+LEMON_IO_API
+ void
+ LemonAsyncSendTo(
+ __lemon_in LemonIO socket,
+ __lemon_in const lemon_byte_t * buffer __lemon_buffer(bufferSize),
+ __lemon_in size_t bufferSize,
+ __lemon_in int flags,
+ __lemon_in const struct sockaddr * address,
+ __lemon_in socklen_t addressSize,
+ __lemon_in LemonIOCallback callback,
+ __lemon_in void *userData,
+ __lemon_inout LemonErrorInfo *errorCode);
+
+LEMON_IO_API
+ size_t
+ LemonReceiveFrom(
+ __lemon_in LemonIO socket,
+ __lemon_in lemon_byte_t * buffer __lemon_buffer(bufferSize),
+ __lemon_in size_t bufferSize,
+ __lemon_in int flags,
+ __lemon_in struct sockaddr * address,
+ __lemon_in socklen_t *addressSize,
+ __lemon_inout LemonErrorInfo *errorCode);
+
+
+LEMON_IO_API
+ void
+ LemonAsyncReceiveFrom(
+ __lemon_in LemonIO socket,
+ __lemon_in lemon_byte_t * buffer __lemon_buffer(bufferSize),
+ __lemon_in size_t bufferSize,
+ __lemon_in int flags,
+ __lemon_in struct sockaddr * address,
+ __lemon_in socklen_t *addressSize,
+ __lemon_in LemonIOCallback callback,
+ __lemon_in void *userData,
+ __lemon_inout LemonErrorInfo *errorCode);
+
#endif //LEMON_IO_H
View
@@ -110,7 +110,7 @@ namespace lemon{namespace io{
}
}
- IOService::IOData * IOService::NewAcceptIOData(Socket * listen, Socket * peer, LemonIOCallback callback,void * userData,sockaddr *address,socklen_t *addressSize)
+ IOService::AcceptIOData * IOService::NewAcceptIOData(Socket * listen, Socket * peer, LemonAcceptCallback callback,void * userData,sockaddr *address,socklen_t *addressSize)
{
mutex_t::scope_lock lock(_acceptIoDataAllocatorMutex);
View
@@ -34,25 +34,26 @@ namespace lemon{namespace io{
class Socket;
- void LemonAcceptCallback(void *userData,size_t numberOfBytesTransferred,const LemonErrorInfo * errorCode);
+ void __AcceptCallback(void *userData,size_t numberOfBytesTransferred,const LemonErrorInfo * errorCode);
- struct AcceptIOData : public IODataT<IOService>
+ template<typename IOService>
+ struct AcceptIODataT : public IODataT<IOService>
{
Socket *Listen;
Socket *Peer;
void *AcceptUserData;
- LemonIOCallback AcceptCallback;
+ LemonAcceptCallback AcceptCallback;
lemon_byte_t AcceptBuffer[LEMON_ACCEPTEX_ADDRESS_LENGTH * 2];
struct sockaddr *Address;
socklen_t *AddressSize;
- AcceptIOData(Socket * listen, Socket * peer, LemonIOCallback callback,void * userData,sockaddr *address,socklen_t *addressSize,IODataT<IOService>::IODataRelease release)
+ AcceptIODataT(Socket * listen, Socket * peer, LemonAcceptCallback callback,void * userData,sockaddr *address,socklen_t *addressSize,IODataT<IOService>::IODataRelease release)
{
Listen = listen;Peer = peer;
@@ -66,7 +67,7 @@ namespace lemon{namespace io{
UserData = this;
- IODataT<IOService>::Callback = &LemonAcceptCallback;
+ IODataT<IOService>::Callback = &__AcceptCallback;
Release = release;
}
@@ -77,7 +78,9 @@ namespace lemon{namespace io{
{
public:
- typedef IODataT<IOService> IOData;
+ typedef IODataT<IOService> IOData;
+
+ typedef AcceptIODataT<IOService> AcceptIOData;
typedef memory::fixed::allocator<sizeof(IOData)> IODataAllocator;
@@ -97,7 +100,7 @@ namespace lemon{namespace io{
void ReleaseIOData(IOData * iodata);
- IOData * NewAcceptIOData(Socket * listen, Socket * peer, LemonIOCallback callback,void * userData,sockaddr *address,socklen_t *addressSize);
+ AcceptIOData * NewAcceptIOData(Socket * listen, Socket * peer, LemonAcceptCallback callback,void * userData,sockaddr *address,socklen_t *addressSize);
void ReleaseAcceptIOData(IOData * iodata);
Oops, something went wrong.

0 comments on commit 9810ef4

Please sign in to comment.