Changeset 1158
- Timestamp:
- Feb 4, 2004, 9:58:31 PM (22 years ago)
- 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
to1.3
r1157 r1158 32 32 #include <sys/socket.h> 33 33 #include <sys/fcntl.h> 34 #include <sys/time.h> 34 35 #include <emx/io.h> 36 #include <emx/libclog.h> 35 37 #include "socket.h" 36 38 … … 61 63 * @param c Number of file descriptors specified in the call. 62 64 * @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 */ 67 static inline int calcsize(int c, const struct fd_set *pFrom, int *pcFDs) 65 68 { 66 69 int cbRet; 70 int i; 67 71 #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; 69 83 #else 70 int i;71 84 for (cbRet = sizeof(u_short), i = 0; i < c; i++) 72 85 if (FD_ISSET(i, pFrom)) 73 86 cbRet++; 87 *pcFDs = c; 74 88 #endif 75 89 if (cbRet < sizeof(struct my_fd_set)) … … 134 148 int bsdselect(int nfds, struct fd_set *readfds, struct fd_set *writefds, struct fd_set *exceptfds, struct timeval *tv) 135 149 { 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); 136 152 #ifdef TCPV40HDRS 137 153 struct fd_set *pRead; … … 143 159 struct v5_fd_set *pExcept; 144 160 #endif 145 int cb;146 161 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 } 147 182 148 183 /* … … 152 187 if (readfds) 153 188 { 154 cb = calcsize(nfds, readfds);155 189 pRead = alloca(cb); 156 190 if (!pRead) 157 191 { 158 192 __libsocket_setErrno(ENOMEM); 159 return -1; 160 } 161 if (convert(nfds, cb, readfds, pRead)) 162 return -1; 193 LIBCLOG_RETURN_INT(-1); 194 } 163 195 } 164 196 … … 166 198 if (writefds) 167 199 { 168 cb = calcsize(nfds, writefds);169 200 pWrite = alloca(cb); 170 201 if (!pWrite) 171 202 { 172 203 __libsocket_setErrno(ENOMEM); 173 return -1; 174 } 175 if (convert(nfds, cb, writefds, pWrite)) 176 return -1; 204 LIBCLOG_RETURN_INT(-1); 205 } 177 206 } 178 207 … … 180 209 if (exceptfds) 181 210 { 182 cb = calcsize(nfds, exceptfds);183 211 pExcept = alloca(cb); 184 212 if (!pExcept) 185 213 { 186 214 __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 { 189 236 if (convert(nfds, cb, exceptfds, pExcept)) 190 return -1;237 LIBCLOG_RETURN_INT(-1); 191 238 } 192 239 … … 194 241 * Do the call. 195 242 */ 196 rc = __libsocket_bsdselect( nfds, pRead, pWrite, pExcept, tv);243 rc = __libsocket_bsdselect(cFDs, pRead, pWrite, pExcept, tv); 197 244 if (rc < 0) 198 245 { 199 246 __libsocket_setLibcErrno(); 200 return rc;247 LIBCLOG_RETURN_INT(rc); 201 248 } 202 249 … … 214 261 if (exceptfds) 215 262 memset(exceptfds, 0, cb); 216 return 0;263 LIBCLOG_RETURN_INT(0); 217 264 } 218 265 … … 227 274 update(nfds, pExcept, exceptfds); 228 275 229 return rc;230 } 231 232 233 276 LIBCLOG_RETURN_INT(rc); 277 } 278 279 280 -
Property cvs2svn:cvs-rev
changed from
-
trunk/src/emx/src/lib/socket/socket.smak
-
Property cvs2svn:cvs-rev
changed from
1.12
to1.13
r1157 r1158 19 19 include mkimplib.smak 20 20 21 .TARGET := libsocket_l.a 22 .TKIND := aout log 23 .TKEEP := 1 24 include mkimplib.smak 25 21 26 .TARGET := libsocket.a 22 27 .TKIND := aout … … 24 29 include mkimplib.smak 25 30 31 26 32 27 33 .TARGET := libsocket_p.a … … 36 42 include mkimplib.smak 37 43 44 .TARGET := libsocket_l.a 45 .TKIND := aout log 46 .TKEEP := 1 47 include mkimplib.smak 48 38 49 .TARGET := libsocket.a 39 50 .TKIND := aout -
Property cvs2svn:cvs-rev
changed from
-
trunk/src/emx/src/libsocket/bsdselect.c
-
Property cvs2svn:cvs-rev
changed from
1.2
to1.3
r1157 r1158 32 32 #include <sys/socket.h> 33 33 #include <sys/fcntl.h> 34 #include <sys/time.h> 34 35 #include <emx/io.h> 36 #include <emx/libclog.h> 35 37 #include "socket.h" 36 38 … … 61 63 * @param c Number of file descriptors specified in the call. 62 64 * @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 */ 67 static inline int calcsize(int c, const struct fd_set *pFrom, int *pcFDs) 65 68 { 66 69 int cbRet; 70 int i; 67 71 #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; 69 83 #else 70 int i;71 84 for (cbRet = sizeof(u_short), i = 0; i < c; i++) 72 85 if (FD_ISSET(i, pFrom)) 73 86 cbRet++; 87 *pcFDs = c; 74 88 #endif 75 89 if (cbRet < sizeof(struct my_fd_set)) … … 134 148 int bsdselect(int nfds, struct fd_set *readfds, struct fd_set *writefds, struct fd_set *exceptfds, struct timeval *tv) 135 149 { 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); 136 152 #ifdef TCPV40HDRS 137 153 struct fd_set *pRead; … … 143 159 struct v5_fd_set *pExcept; 144 160 #endif 145 int cb;146 161 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 } 147 182 148 183 /* … … 152 187 if (readfds) 153 188 { 154 cb = calcsize(nfds, readfds);155 189 pRead = alloca(cb); 156 190 if (!pRead) 157 191 { 158 192 __libsocket_setErrno(ENOMEM); 159 return -1; 160 } 161 if (convert(nfds, cb, readfds, pRead)) 162 return -1; 193 LIBCLOG_RETURN_INT(-1); 194 } 163 195 } 164 196 … … 166 198 if (writefds) 167 199 { 168 cb = calcsize(nfds, writefds);169 200 pWrite = alloca(cb); 170 201 if (!pWrite) 171 202 { 172 203 __libsocket_setErrno(ENOMEM); 173 return -1; 174 } 175 if (convert(nfds, cb, writefds, pWrite)) 176 return -1; 204 LIBCLOG_RETURN_INT(-1); 205 } 177 206 } 178 207 … … 180 209 if (exceptfds) 181 210 { 182 cb = calcsize(nfds, exceptfds);183 211 pExcept = alloca(cb); 184 212 if (!pExcept) 185 213 { 186 214 __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 { 189 236 if (convert(nfds, cb, exceptfds, pExcept)) 190 return -1;237 LIBCLOG_RETURN_INT(-1); 191 238 } 192 239 … … 194 241 * Do the call. 195 242 */ 196 rc = __libsocket_bsdselect( nfds, pRead, pWrite, pExcept, tv);243 rc = __libsocket_bsdselect(cFDs, pRead, pWrite, pExcept, tv); 197 244 if (rc < 0) 198 245 { 199 246 __libsocket_setLibcErrno(); 200 return rc;247 LIBCLOG_RETURN_INT(rc); 201 248 } 202 249 … … 214 261 if (exceptfds) 215 262 memset(exceptfds, 0, cb); 216 return 0;263 LIBCLOG_RETURN_INT(0); 217 264 } 218 265 … … 227 274 update(nfds, pExcept, exceptfds); 228 275 229 return rc;230 } 231 232 233 276 LIBCLOG_RETURN_INT(rc); 277 } 278 279 280 -
Property cvs2svn:cvs-rev
changed from
-
trunk/src/emx/src/libsocket/socket.smak
-
Property cvs2svn:cvs-rev
changed from
1.12
to1.13
r1157 r1158 19 19 include mkimplib.smak 20 20 21 .TARGET := libsocket_l.a 22 .TKIND := aout log 23 .TKEEP := 1 24 include mkimplib.smak 25 21 26 .TARGET := libsocket.a 22 27 .TKIND := aout … … 24 29 include mkimplib.smak 25 30 31 26 32 27 33 .TARGET := libsocket_p.a … … 36 42 include mkimplib.smak 37 43 44 .TARGET := libsocket_l.a 45 .TKIND := aout log 46 .TKEEP := 1 47 include mkimplib.smak 48 38 49 .TARGET := libsocket.a 39 50 .TKIND := aout -
Property cvs2svn:cvs-rev
changed from
Note:
See TracChangeset
for help on using the changeset viewer.