Changeset 222

Show
Ignore:
Timestamp:
23/05/07 15:09:05 (18 months ago)
Author:
ono
Message:

mio fixed for Windows platform:
* select requires 3rd exception parameter
* lowfd added for select, because Winsock doesn't start from 1 with descriptors
Services shall use MIO_MAXFD instead of 1024 when calling mio_new, so we are not capped to 1024 on Windows select, since descriptors usually start above.
On Windows we use FD_SETSIZE which is defined to 16k in win32 projects.
Add JABBERD2_API implementation for "mio", required to build proper jabberd2.dll on Windows.
Renamed WIN32 to _WIN32 checks.

Location:
trunk/mio
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • trunk/mio/mio.h

    r3 r222  
    2727 
    2828#include "ac-stdint.h" 
     29 
     30/* jabberd2 Windows DLL */ 
     31#ifndef JABBERD2_API 
     32# ifdef _WIN32 
     33#  ifdef JABBERD2_EXPORTS 
     34#   define JABBERD2_API  __declspec(dllexport) 
     35#  else /* JABBERD2_EXPORTS */ 
     36#   define JABBERD2_API  __declspec(dllimport) 
     37#  endif /* JABBERD2_EXPORTS */ 
     38# else /* _WIN32 */ 
     39#  define JABBERD2_API extern 
     40# endif /* _WIN32 */ 
     41#endif /* JABBERD2_API */ 
     42 
     43#ifdef _WIN32 
     44# define MIO_MAXFD FD_SETSIZE 
     45#else 
     46# define MIO_MAXFD 1024 
     47#endif 
    2948 
    3049#include <stdio.h> 
     
    110129 
    111130/** create/free the mio subsytem */ 
    112 mio_t mio_new(int maxfd); /* returns NULL if failed */ 
     131JABBERD2_API mio_t mio_new(int maxfd); /* returns NULL if failed */ 
    113132 
    114133#define mio_free(m) (*m)->mio_free(m) 
  • trunk/mio/mio_impl.h

    r141 r222  
    2626#include "util/inaddr.h" 
    2727 
     28/* win32 wrappers around strerror */ 
     29#ifdef _WIN32 
     30#define close(x) closesocket(x) 
     31#ifdef MIO_DEBUG 
     32char *ws_strerror(int code) 
     33{ 
     34    static char buff[128]; 
     35    int len; 
     36    if(FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, 
     37                NULL, WSAGetLastError(), 0, buff, 
     38                sizeof(buff), NULL)) 
     39        return buff; 
     40    return strerror(code); 
     41} 
     42#define strerror(x) ws_strerror(x) 
     43#endif 
     44#endif /* _WIN32 */ 
     45 
    2846/** our internal wrapper around a fd */ 
    2947typedef enum {  
     
    392410 
    393411    /* gotta wait till later */ 
     412#ifdef _WIN32 
     413    if(flag == -1 && WSAGetLastError() == WSAEWOULDBLOCK) 
     414#else 
    394415    if(flag == -1 && errno == EINPROGRESS) 
     416#endif 
    395417    { 
    396418        mio_fd = _mio_setup_fd(m,fd,app,arg); 
     
    432454    mio_t m; 
    433455 
     456    /* init winsock if we are in Windows */ 
     457#ifdef _WIN32 
     458    WSADATA wsaData; 
     459    if (WSAStartup(MAKEWORD( 1, 1 ), &wsaData)) 
     460        return NULL; 
     461#endif 
     462 
    434463    /* allocate and zero out main memory */ 
    435464    if((m = malloc(sizeof(struct mio_priv_st))) == NULL) return NULL; 
  • trunk/mio/mio_select.h

    r3 r222  
    3434        }                                                               \ 
    3535        m->highfd = 0;                                                  \ 
     36        m->lowfd = m->maxfd;                                            \ 
    3637    }                                                                   \ 
    3738                                                                        \ 
     
    3940    {                                                                   \ 
    4041        if(fd > m->highfd) m->highfd = fd;                              \ 
     42        if(fd < m->lowfd) m->lowfd = fd;                                \ 
    4143        return &m->fds[fd].mio_fd;                                      \ 
    4244    }                                                                   \ 
     
    5153        tv.tv_sec = t;                                                  \ 
    5254        tv.tv_usec = 0;                                                 \ 
    53         return select(m->highfd + 1, &m->rfds_out, &m->wfds_out, NULL, &tv); \ 
     55        return select(m->highfd + 1, &m->rfds_out, &m->wfds_out, &m->wfds_out, &tv); \ 
    5456    } 
    5557 
     
    5860#define MIO_VARS \ 
    5961    struct mio_priv_fd_st *fds;                                         \ 
     62    int lowfd;                                                          \ 
    6063    int highfd;                                                         \ 
    6164    fd_set rfds_in, wfds_in, rfds_out, wfds_out; 
     
    106109 
    107110#define MIO_ITERATE_RESULTS(m, retval, iter) \ 
    108     for(iter = 0; iter <= MIO(m)->highfd; iter++) 
     111    for(iter = MIO(m)->lowfd; iter <= MIO(m)->highfd; iter++) 
    109112 
    110113#define MIO_ITERATOR_FD(m, iter) \