Changeset 1158


Ignore:
Timestamp:
Feb 4, 2004, 9:58:31 PM (22 years ago)
Author:
bird
Message:

Logging and fixing.

Location:
trunk/src/emx/src
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/emx/src/lib/socket/bsdselect.c

    • Property cvs2svn:cvs-rev changed from 1.2 to 1.3
    r1157 r1158  
    3232#include <sys/socket.h>
    3333#include <sys/fcntl.h>
     34#include <sys/time.h>
    3435#include <emx/io.h>
     36#include <emx/libclog.h>
    3537#include "socket.h"
    3638
     
    6163 * @param   c       Number of file descriptors specified in the call.
    6264 * @param   pFrom   The select input fd_set structure.
    63  */
    64 static inline int calcsize(int c, const struct fd_set *pFrom)
     65 * @parm    pcFDs   Store the new number of file descriptors (socket handles) to examin.
     66 */
     67static inline int calcsize(int c, const struct fd_set *pFrom, int *pcFDs)
    6568{
    6669    int cbRet;
     70    int i;
    6771#ifdef TCPV40HDRS
    68     cbRet = (c + 7) / 8;
     72    /* here we need to figure out the max real socket handle */
     73    int iMax = *pcFDs - 1;
     74    for (iMax = 0, i = 0; i < c; i++)
     75        if (FD_ISSET(i, pFrom))
     76        {
     77            PLIBCSOCKETFH   pFHSocket = __libsocket_FH(i);
     78            if (pFHSocket && iMax < pFHSocket->iSocket)
     79                iMax = pFHSocket->iSocket;
     80        }
     81    cbRet = (iMax + 8) / 8;             /* iMax is index not count, thus +8 not +7. */
     82    *pcFDs = iMax + 1;
    6983#else
    70     int i;
    7184    for (cbRet = sizeof(u_short), i = 0; i < c; i++)
    7285        if (FD_ISSET(i, pFrom))
    7386            cbRet++;
     87    *pcFDs = c;
    7488#endif
    7589    if (cbRet < sizeof(struct my_fd_set))
     
    134148int bsdselect(int nfds, struct fd_set *readfds, struct fd_set *writefds, struct fd_set *exceptfds, struct timeval *tv)
    135149{
     150    LIBCLOG_ENTER("nfds=%d readfds=%p writefds=%p exceptfds=%d tv=%p={tv_sec=%d, rv_usec=%d}\n",
     151                  nfds, readfds, writefds, exceptfds, tv, tv ? tv->tv_sec : -1, tv ? tv->tv_usec : -1);
    136152#ifdef TCPV40HDRS
    137153    struct fd_set      *pRead;
     
    143159    struct v5_fd_set   *pExcept;
    144160#endif
    145     int                 cb;
    146161    int                 rc;
     162    int                 cb = 0;
     163    int                 cFDs = 0;
     164
     165    /*
     166     * Calculate bitmapsize.
     167     */
     168    if (readfds)
     169        cb = calcsize(nfds, readfds, &cFDs);
     170    if (writefds)
     171    {
     172        int cbT = calcsize(nfds, writefds, &cFDs);
     173        if (cbT > cb)
     174            cb = cbT;
     175    }
     176    if (exceptfds)
     177    {
     178        int cbT = calcsize(nfds, exceptfds, &cFDs);
     179        if (cbT > cb)
     180            cb = cbT;
     181    }
    147182
    148183    /*
     
    152187    if (readfds)
    153188    {
    154         cb = calcsize(nfds, readfds);
    155189        pRead = alloca(cb);
    156190        if (!pRead)
    157191        {
    158192            __libsocket_setErrno(ENOMEM);
    159             return -1;
    160         }
    161         if (convert(nfds, cb, readfds, pRead))
    162             return -1;
     193            LIBCLOG_RETURN_INT(-1);
     194        }
    163195    }
    164196
     
    166198    if (writefds)
    167199    {
    168         cb = calcsize(nfds, writefds);
    169200        pWrite = alloca(cb);
    170201        if (!pWrite)
    171202        {
    172203            __libsocket_setErrno(ENOMEM);
    173             return -1;
    174         }
    175         if (convert(nfds, cb, writefds, pWrite))
    176             return -1;
     204            LIBCLOG_RETURN_INT(-1);
     205        }
    177206    }
    178207
     
    180209    if (exceptfds)
    181210    {
    182         cb = calcsize(nfds, exceptfds);
    183211        pExcept = alloca(cb);
    184212        if (!pExcept)
    185213        {
    186214            __libsocket_setErrno(ENOMEM);
    187             return -1;
    188         }
     215            LIBCLOG_RETURN_INT(-1);
     216        }
     217    }
     218
     219    /*
     220     * Convert the bitmaps.
     221     */
     222    if (readfds)
     223    {
     224        if (convert(nfds, cb, readfds, pRead))
     225            LIBCLOG_RETURN_INT(-1);
     226    }
     227
     228    if (writefds)
     229    {
     230        if (convert(nfds, cb, writefds, pWrite))
     231            LIBCLOG_RETURN_INT(-1);
     232    }
     233
     234    if (exceptfds)
     235    {
    189236        if (convert(nfds, cb, exceptfds, pExcept))
    190             return -1;
     237            LIBCLOG_RETURN_INT(-1);
    191238    }
    192239
     
    194241     * Do the call.
    195242     */
    196     rc = __libsocket_bsdselect(nfds, pRead, pWrite, pExcept, tv);
     243    rc = __libsocket_bsdselect(cFDs, pRead, pWrite, pExcept, tv);
    197244    if (rc < 0)
    198245    {
    199246        __libsocket_setLibcErrno();
    200         return rc;
     247        LIBCLOG_RETURN_INT(rc);
    201248    }
    202249
     
    214261        if (exceptfds)
    215262            memset(exceptfds, 0, cb);
    216         return 0;
     263        LIBCLOG_RETURN_INT(0);
    217264    }
    218265
     
    227274        update(nfds, pExcept, exceptfds);
    228275
    229     return rc;
    230 }
    231 
    232 
    233 
     276    LIBCLOG_RETURN_INT(rc);
     277}
     278
     279
     280
  • trunk/src/emx/src/lib/socket/socket.smak

    • Property cvs2svn:cvs-rev changed from 1.12 to 1.13
    r1157 r1158  
    1919include mkimplib.smak
    2020
     21.TARGET := libsocket_l.a
     22.TKIND  := aout log
     23.TKEEP  := 1
     24include mkimplib.smak
     25
    2126.TARGET := libsocket.a
    2227.TKIND  := aout
     
    2429include mkimplib.smak
    2530
     31               
    2632       
    2733.TARGET := libsocket_p.a
     
    3642include mkimplib.smak
    3743
     44.TARGET := libsocket_l.a
     45.TKIND  := aout log
     46.TKEEP  := 1
     47include mkimplib.smak
     48
    3849.TARGET := libsocket.a
    3950.TKIND  := aout
  • trunk/src/emx/src/libsocket/bsdselect.c

    • Property cvs2svn:cvs-rev changed from 1.2 to 1.3
    r1157 r1158  
    3232#include <sys/socket.h>
    3333#include <sys/fcntl.h>
     34#include <sys/time.h>
    3435#include <emx/io.h>
     36#include <emx/libclog.h>
    3537#include "socket.h"
    3638
     
    6163 * @param   c       Number of file descriptors specified in the call.
    6264 * @param   pFrom   The select input fd_set structure.
    63  */
    64 static inline int calcsize(int c, const struct fd_set *pFrom)
     65 * @parm    pcFDs   Store the new number of file descriptors (socket handles) to examin.
     66 */
     67static inline int calcsize(int c, const struct fd_set *pFrom, int *pcFDs)
    6568{
    6669    int cbRet;
     70    int i;
    6771#ifdef TCPV40HDRS
    68     cbRet = (c + 7) / 8;
     72    /* here we need to figure out the max real socket handle */
     73    int iMax = *pcFDs - 1;
     74    for (iMax = 0, i = 0; i < c; i++)
     75        if (FD_ISSET(i, pFrom))
     76        {
     77            PLIBCSOCKETFH   pFHSocket = __libsocket_FH(i);
     78            if (pFHSocket && iMax < pFHSocket->iSocket)
     79                iMax = pFHSocket->iSocket;
     80        }
     81    cbRet = (iMax + 8) / 8;             /* iMax is index not count, thus +8 not +7. */
     82    *pcFDs = iMax + 1;
    6983#else
    70     int i;
    7184    for (cbRet = sizeof(u_short), i = 0; i < c; i++)
    7285        if (FD_ISSET(i, pFrom))
    7386            cbRet++;
     87    *pcFDs = c;
    7488#endif
    7589    if (cbRet < sizeof(struct my_fd_set))
     
    134148int bsdselect(int nfds, struct fd_set *readfds, struct fd_set *writefds, struct fd_set *exceptfds, struct timeval *tv)
    135149{
     150    LIBCLOG_ENTER("nfds=%d readfds=%p writefds=%p exceptfds=%d tv=%p={tv_sec=%d, rv_usec=%d}\n",
     151                  nfds, readfds, writefds, exceptfds, tv, tv ? tv->tv_sec : -1, tv ? tv->tv_usec : -1);
    136152#ifdef TCPV40HDRS
    137153    struct fd_set      *pRead;
     
    143159    struct v5_fd_set   *pExcept;
    144160#endif
    145     int                 cb;
    146161    int                 rc;
     162    int                 cb = 0;
     163    int                 cFDs = 0;
     164
     165    /*
     166     * Calculate bitmapsize.
     167     */
     168    if (readfds)
     169        cb = calcsize(nfds, readfds, &cFDs);
     170    if (writefds)
     171    {
     172        int cbT = calcsize(nfds, writefds, &cFDs);
     173        if (cbT > cb)
     174            cb = cbT;
     175    }
     176    if (exceptfds)
     177    {
     178        int cbT = calcsize(nfds, exceptfds, &cFDs);
     179        if (cbT > cb)
     180            cb = cbT;
     181    }
    147182
    148183    /*
     
    152187    if (readfds)
    153188    {
    154         cb = calcsize(nfds, readfds);
    155189        pRead = alloca(cb);
    156190        if (!pRead)
    157191        {
    158192            __libsocket_setErrno(ENOMEM);
    159             return -1;
    160         }
    161         if (convert(nfds, cb, readfds, pRead))
    162             return -1;
     193            LIBCLOG_RETURN_INT(-1);
     194        }
    163195    }
    164196
     
    166198    if (writefds)
    167199    {
    168         cb = calcsize(nfds, writefds);
    169200        pWrite = alloca(cb);
    170201        if (!pWrite)
    171202        {
    172203            __libsocket_setErrno(ENOMEM);
    173             return -1;
    174         }
    175         if (convert(nfds, cb, writefds, pWrite))
    176             return -1;
     204            LIBCLOG_RETURN_INT(-1);
     205        }
    177206    }
    178207
     
    180209    if (exceptfds)
    181210    {
    182         cb = calcsize(nfds, exceptfds);
    183211        pExcept = alloca(cb);
    184212        if (!pExcept)
    185213        {
    186214            __libsocket_setErrno(ENOMEM);
    187             return -1;
    188         }
     215            LIBCLOG_RETURN_INT(-1);
     216        }
     217    }
     218
     219    /*
     220     * Convert the bitmaps.
     221     */
     222    if (readfds)
     223    {
     224        if (convert(nfds, cb, readfds, pRead))
     225            LIBCLOG_RETURN_INT(-1);
     226    }
     227
     228    if (writefds)
     229    {
     230        if (convert(nfds, cb, writefds, pWrite))
     231            LIBCLOG_RETURN_INT(-1);
     232    }
     233
     234    if (exceptfds)
     235    {
    189236        if (convert(nfds, cb, exceptfds, pExcept))
    190             return -1;
     237            LIBCLOG_RETURN_INT(-1);
    191238    }
    192239
     
    194241     * Do the call.
    195242     */
    196     rc = __libsocket_bsdselect(nfds, pRead, pWrite, pExcept, tv);
     243    rc = __libsocket_bsdselect(cFDs, pRead, pWrite, pExcept, tv);
    197244    if (rc < 0)
    198245    {
    199246        __libsocket_setLibcErrno();
    200         return rc;
     247        LIBCLOG_RETURN_INT(rc);
    201248    }
    202249
     
    214261        if (exceptfds)
    215262            memset(exceptfds, 0, cb);
    216         return 0;
     263        LIBCLOG_RETURN_INT(0);
    217264    }
    218265
     
    227274        update(nfds, pExcept, exceptfds);
    228275
    229     return rc;
    230 }
    231 
    232 
    233 
     276    LIBCLOG_RETURN_INT(rc);
     277}
     278
     279
     280
  • trunk/src/emx/src/libsocket/socket.smak

    • Property cvs2svn:cvs-rev changed from 1.12 to 1.13
    r1157 r1158  
    1919include mkimplib.smak
    2020
     21.TARGET := libsocket_l.a
     22.TKIND  := aout log
     23.TKEEP  := 1
     24include mkimplib.smak
     25
    2126.TARGET := libsocket.a
    2227.TKIND  := aout
     
    2429include mkimplib.smak
    2530
     31               
    2632       
    2733.TARGET := libsocket_p.a
     
    3642include mkimplib.smak
    3743
     44.TARGET := libsocket_l.a
     45.TKIND  := aout log
     46.TKEEP  := 1
     47include mkimplib.smak
     48
    3849.TARGET := libsocket.a
    3950.TKIND  := aout
Note: See TracChangeset for help on using the changeset viewer.