block.h
上传用户:sddyfurun
上传日期:2007-01-04
资源大小:525k
文件大小:3k
源码类别:

代理服务器

开发平台:

Unix_Linux

  1. /* Copyright (c) 1995,1996,1997 NEC Corporation.  All rights reserved.       */
  2. /*                                                                           */
  3. /* The redistribution, use and modification in source or binary forms of     */
  4. /* this software is subject to the conditions set forth in the copyright     */
  5. /* document ("Copyright") included with this distribution.                   */
  6. /*
  7.  * $Id: block.h,v 1.6 1997/06/16 15:28:48 steve Exp $
  8.  */
  9. #ifndef BLOCK_H
  10. #define BLOCK_H
  11. #if defined(HAVE_FCNTL_H) || defined(HAVE_SYS_FCNTL_H)
  12. #ifdef HAVE_FCNTL_H
  13. #include <fcntl.h>
  14. #endif
  15. #ifdef HAVE_SYS_FCNTL_H
  16. #include <sys/fcntl.h>
  17. #endif
  18. /* some nonblock derivative                                                  */
  19. #ifdef O_NONBLOCK
  20. #define S5_NONBLOCK O_NONBLOCK
  21. #elif defined(FNONBLOCK)
  22. #define S5_NONBLOCK FNONBLOCK
  23. #elif defined(FNONBLK)
  24. #define S5_NONBLOCK FNONBLK
  25. #else
  26. #define S5_NONBLOCK 0
  27. #endif
  28. /* some ndelay derivative                                                    */
  29. #ifdef O_NDELAY
  30. #define S5_NDELAY O_NDELAY
  31. #elif defined(FNDELAY)
  32. #define S5_NDELAY FNDELAY
  33. #else
  34. #define S5_NDELAY 0
  35. #endif
  36. /* pick nonblock first when making things nonblocking -- it's posix          */
  37. /* if it doesn't exist, ndelay will work ok...                               */
  38. /* #if S5_NONBLOCK != 0       */
  39. /* #define NBFLAG S5_NONBLOCK */
  40. /* #else                      */
  41. /* #define NBFLAG S5_NDELAY   */
  42. /* #endif                     */
  43. /* this is just to see if it is nonblocking.  We don't care which is set     */
  44. /* #define NBFLAGS (S5_NONBLOCK | S5_NDELAY)                                 */
  45. #define ISNBLOCK(fd)        (fcntl((fd), F_GETFL, 0) & (S5_NONBLOCK | S5_NDELAY))
  46. #define ISBLOCK(fd)         (!ISNBLOCK((fd)))
  47. /* #define GETFLAGS(fd, flags) (flags = fcntl((fd), F_GETFL, 0))                     */
  48. /* #define BLOCK(fd, flags, nflags) do {                                            */
  49. /*     GETFLAGS((fd), (flags)); (nflags) = (flags);                                 */
  50. /*     if (ISNBLOCK((flags))) fcntl((fd), F_SETFL, (nflags) = (flags) & ~NBFLAGS);  */
  51. /* } while (0) */
  52. /* #define UNBLOCK(fd, flags, nflags) do {                                          */
  53. /*     GETFLAGS((fd), (flags)); (nflags) = (flags);                                 */
  54. /*     if (ISBLOCK((flags))) fcntl((fd), F_SETFL, (nflags) = (flags) | NBFLAG);     */
  55. /* } while (0) */
  56. /* #define RSTBLOCK(fd, flags, nflags)                           */
  57. /*     if ((flags) != (nflags)) fcntl((fd), F_SETFL, (flags))     */
  58. #else
  59. #define ISNBLOCK(fd)  0
  60. #define ISBLOCK(fd)   1
  61. #endif
  62. #endif