summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Sustrik <sustrik@250bpm.com>2012-02-16 10:04:57 +0900
committerMartin Sustrik <sustrik@250bpm.com>2012-02-16 10:04:57 +0900
commitb67f88a7d6322a293ac3e3be9d6df9f358509221 (patch)
tree099f6ef399204a0aadfd31fcd6f7494267901dfa
parentaaa766acf7596eb4de7afe6ae0121335f4fd05da (diff)
Valid handle_t is never NULL
poll_t and select_t polling mechanism convert fd into void*. When fd 0 was converted NULL pointer resulted. Fixed. Signed-off-by: Martin Sustrik <sustrik@250bpm.com>
-rw-r--r--src/fd.hpp30
1 files changed, 24 insertions, 6 deletions
diff --git a/src/fd.hpp b/src/fd.hpp
index d994637..8c9f2a8 100644
--- a/src/fd.hpp
+++ b/src/fd.hpp
@@ -35,19 +35,37 @@ namespace xs
#if defined _MSC_VER &&_MSC_VER <= 1400
typedef UINT_PTR fd_t;
enum {retired_fd = (fd_t)(~0)};
- inline void *fdtoptr (fd_t fd_) {return (void*) fd_;}
- inline fd_t ptrtofd (void *ptr_) {return (fd_t) ptr_;}
+ inline void *fdtoptr (fd_t fd_)
+ {
+ return (void*) (fd_ + 1);
+ }
+ inline fd_t ptrtofd (void *ptr_)
+ {
+ return ((fd_t) ptr_) - 1;
+ }
#else
typedef SOCKET fd_t;
enum {retired_fd = INVALID_SOCKET};
- inline void *fdtoptr (fd_t fd_) {return (void*) fd_;}
- inline fd_t ptrtofd (void *ptr_) {return (fd_t) ptr_;}
+ inline void *fdtoptr (fd_t fd_)
+ {
+ return (void*) (fd_ + 1);
+ }
+ inline fd_t ptrtofd (void *ptr_)
+ {
+ return ((fd_t) ptr_) - 1;
+ }
#endif
#else
typedef int fd_t;
enum {retired_fd = -1};
- inline void *fdtoptr (fd_t fd_) {return (void*) fd_;}
- inline fd_t ptrtofd (void *ptr_) {return (int) ((char*) ptr_ - (char*) 0);}
+ inline void *fdtoptr (fd_t fd_)
+ {
+ return (void*) (fd_ + 1);
+ }
+ inline fd_t ptrtofd (void *ptr_)
+ {
+ return ((int) ((char*) ptr_ - (char*) 0)) - 1;
+ }
#endif
}