Show
Ignore:
Timestamp:
06/03/10 22:43:33 (2 years ago)
Author:
mwhitworth
Message:

Add to network stack.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • Whitix/branches/netchannel/user/sdk/network/aio.c

    r2090 r2099  
    55#include <pthread.h> 
    66 
    7 int globalAioThr; 
    8 int aioWork; 
    9 struct AioCtx* workHead; 
    10 pthread_mutex_t workLock; 
    11  
    12 int SocketAsyncThreaded(Socket* socket) 
     7int SocketAsyncRecv(Socket* socket, struct AsyncCtx* ctx, char* buffer, int length) 
    138{ 
    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; 
    3412 
    3513        return AIO_SUCCESS; 
    3614} 
    3715 
    38 int SocketAsyncSend(Socket* socket, struct AioCtx* aio, char* buffer, int len, int flags) 
     16int SocketAsyncSend(Socket* socket, struct AsyncCtx* aio, char* buffer, int len, int flags) 
    3917{ 
    4018        /* Add to queue */ 
     
    4220} 
    4321 
    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) 
     22int SocketAioCancel(struct AsyncCtx* aio) 
    6523{ 
    6624        return 0; 
    6725} 
    6826 
    69 int SocketAioError(struct AioCtx* aio) 
     27int SocketAioError(struct AsyncCtx* aio) 
    7028{ 
    7129        return 0; 
    7230} 
    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 }