Changeset 2099 for Whitix/branches/netchannel/user/sdk/network/aio.c
- Timestamp:
- 06/03/10 22:43:33 (2 years ago)
- Files:
-
- 1 modified
-
Whitix/branches/netchannel/user/sdk/network/aio.c (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
Whitix/branches/netchannel/user/sdk/network/aio.c
r2090 r2099 5 5 #include <pthread.h> 6 6 7 int globalAioThr; 8 int aioWork; 9 struct AioCtx* workHead; 10 pthread_mutex_t workLock; 11 12 int SocketAsyncThreaded(Socket* socket) 7 int SocketAsyncRecv(Socket* socket, struct AsyncCtx* ctx, char* buffer, int length) 13 8 { 14 printf("Create thread to handle async requests separately\n"); 15 return 0; 16 } 17 18 int SocketAioCreate(struct AioCtx* aio, AioCallback func, int flags) 19 { 20 aio->magic = AIO_MAGIC; 21 aio->func = func; 22 aio->prev = aio->next = NULL; 23 aio->flags = flags; 24 25 return 0; 26 } 27 28 int SocketAsyncRecv(Socket* socket, struct AioCtx* aio) 29 { 30 if (aio->magic != AIO_MAGIC) 31 return AIO_INVALID; 32 33 socket->recvAio = aio; 9 socket->recvAio = ctx; 10 ctx->buffer = buffer; 11 ctx->bufferSize = length; 34 12 35 13 return AIO_SUCCESS; 36 14 } 37 15 38 int SocketAsyncSend(Socket* socket, struct A ioCtx* aio, char* buffer, int len, int flags)16 int SocketAsyncSend(Socket* socket, struct AsyncCtx* aio, char* buffer, int len, int flags) 39 17 { 40 18 /* Add to queue */ … … 42 20 } 43 21 44 void AioWorkerThread(void* data); 45 46 int SocketAioFire(Socket* socket, struct AioCtx* aio, int len) 47 { 48 if (!globalAioThr) 49 { 50 globalAioThr = SysCreateThread((unsigned long)AioWorkerThread, 0, NULL); 51 pthread_mutex_init(&workLock, NULL); 52 } 53 54 aio->length = len; 55 workHead = aio; 56 57 aioWork = 1; 58 SysResumeThread(globalAioThr); 59 SysYield(); 60 61 return 0; 62 } 63 64 int SocketAioCancel(struct AioCtx* aio) 22 int SocketAioCancel(struct AsyncCtx* aio) 65 23 { 66 24 return 0; 67 25 } 68 26 69 int SocketAioError(struct A ioCtx* aio)27 int SocketAioError(struct AsyncCtx* aio) 70 28 { 71 29 return 0; 72 30 } 73 74 int SocketAioReturn(struct AioCtx* aio)75 {76 return 0;77 }78 79 void AioWorkerThread(void* data)80 {81 /* Main thread */82 struct AioCtx* curr;83 84 while (1)85 {86 if (!workHead)87 SysSuspendThread(-1);88 89 curr = workHead;90 workHead = NULL;91 92 if (!curr)93 continue;94 95 if (curr->func)96 curr->func(curr);97 }98 }
