⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sockdef.pas

📁 提供串行口存取的 Object Pascal 类 ( 1.2 版
💻 PAS
📖 第 1 页 / 共 2 页
字号:
unit SockDef;
(*
**
** SOCKDEF routines
**
** Copyright (c) 1998 by Thomas W. Mueller
**
** Created : 24-Oct-1998
** Last update : 24-Oct-1998
**
**
*)

(*-+-*-+-*-+-*-+-*-+-*-+-*-+-*-+-*-+-*-+-*-+-*-+-*-+-*-+-*-+-*-+-*-+-*-+-*-*)
 INTERFACE
(*-+-*-+-*-+-*-+-*-+-*-+-*-+-*-+-*-+-*-+-*-+-*-+-*-+-*-+-*-+-*-+-*-+-*-+-*-*)

uses
  Sysutils,
{$IFDEF OS2}
  Os2def;
{$ENDIF}
{$IFDEF LINUX}
  Linux;
{$ENDIF}
{$IFDEF WIN32}
  Windows;
{$ENDIF}

(*-+-*-+-*-+-*-+-*-+-*-+-*-+-*-+-*-+-*-+-*-+-*-+-*-+-*-+-*-+-*-+-*-+-*-+-*-*)

{$IFDEF VER0_99_13}
type pInteger = ^Integer;
     tFarProc = pointer;
     SmallInt = System.Integer;
{$ENDIF}

{$IFDEF LINUX}
type ULONG    = longint;
{$ENDIF}

type
  tSockDesc  = LongInt;
  SmallWord  = System.Word;

type
  eSocketErr = class(Exception);

(*-+-*-+-*-+-*-+-*-+-*-+-*-+-*-+-*-+-*-+-*-+-*-+-*-+-*-+-*-+-*-+-*-+-*-+-*-*)

const
  MaxHostNameLen = 120;

(*
** Option flags per-socket.
*)
{$IFNDEF LINUX}
(*
** Level number for (get/set)sockopt() to apply to socket itself.
*)
  SOL_SOCKET      =$ffff;          // options for socket level

  SO_DEBUG        =$0001;          // turn on debugging info recording
  SO_ACCEPTCONN   =$0002;          // socket has had listen()
  SO_REUSEADDR    =$0004;          // allow local address reuse
  SO_KEEPALIVE    =$0008;          // keep connections alive
  SO_DONTROUTE    =$0010;          // just use interface addresses
  SO_BROADCAST    =$0020;          // permit sending of broadcast msgs
  SO_USELOOPBACK  =$0040;          // bypass hardware when possible
  SO_LINGER       =$0080;          // linger on close if data present
  SO_OOBINLINE    =$0100;          // leave received OOB data in line

(*
** Additional options, not kept in so_options.
*)
  SO_SNDBUF       =$1001;          // send buffer size
  SO_RCVBUF       =$1002;          // receive buffer size
  SO_SNDLOWAT     =$1003;          // send low-water mark
  SO_RCVLOWAT     =$1004;          // receive low-water mark
  SO_SNDTIMEO     =$1005;          // send timeout
  SO_RCVTIMEO     =$1006;          // receive timeout
  SO_ERROR        =$1007;          // get error status and clear
  SO_TYPE         =$1008;          // get socket type

{$ELSE}
  SOL_SOCKET      = 1;

  SO_DEBUG        = 1;
  SO_REUSEADDR    = 2;
  SO_TYPE         = 3;
  SO_ERROR        = 4;
  SO_DONTROUTE    = 5;
  SO_BROADCAST    = 6;
  SO_SNDBUF       = 7;
  SO_RCVBUF       = 8;
  SO_KEEPALIVE    = 9;
  SO_OOBINLINE    = 10;
  SO_NO_CHECK     = 11;
  SO_PRIORITY     = 12;
  SO_LINGER       = 13;
  SO_BSDCOMPAT    = 14;
{$ENDIF}


(*
** Address families.
*)
  AF_UNSPEC      =  0;              // unspecified
  AF_UNIX        =  1;              // local to host (pipes, portals)
  AF_INET        =  2;              // internetwork: UDP, TCP, etc.
  AF_IMPLINK     =  3;              // arpanet imp addresses
  AF_PUP         =  4;              // pup protocols: e.g. BSP
  AF_CHAOS       =  5;              // mit CHAOS protocols
  AF_NS          =  6;              // XEROX NS protocols
  AF_NBS         =  7;              // nbs protocols
  AF_ECMA        =  8;              // european computer manufacturers
  AF_DATAKIT     =  9;              // datakit protocols
  AF_CCITT       = 10;              // CCITT protocols, X.25 etc
  AF_SNA         = 11;              // IBM SNA
  AF_DECnet      = 12;              // DECnet
  AF_DLI         = 13;              // Direct data link interface
  AF_LAT         = 14;              // LAT
  AF_HYLINK      = 15;              // NSC Hyperchannel
  AF_APPLETALK   = 16;              // Apple Talk

  AF_OS2         = AF_UNIX;

  AF_NB          = 17;                // Netbios
  AF_NETBIOS     = AF_NB;

  AF_MAX         = 18;

(*
** Protocol families, same as address families for now.
*)
  PF_UNSPEC       = AF_UNSPEC;
  PF_UNIX         = AF_UNIX;
  PF_INET         = AF_INET;
  PF_IMPLINK      = AF_IMPLINK;
  PF_PUP          = AF_PUP;
  PF_CHAOS        = AF_CHAOS;
  PF_NS           = AF_NS;
  PF_NBS          = AF_NBS;
  PF_ECMA         = AF_ECMA;
  PF_DATAKIT      = AF_DATAKIT;
  PF_CCITT        = AF_CCITT;
  PF_SNA          = AF_SNA;
  PF_DECnet       = AF_DECnet;
  PF_DLI          = AF_DLI;
  PF_LAT          = AF_LAT;
  PF_HYLINK       = AF_HYLINK;
  PF_APPLETALK    = AF_APPLETALK;
  PF_NETBIOS      = AF_NB;
  PF_NB           = AF_NB;
  PF_OS2          = PF_UNIX;
  PF_MAX          = AF_MAX;

(*
** Maximum queue length specifiable by listen.
*)

  SOMAXCONN       = 5;

  FREAD  =1;
  FWRITE =2;

  MSG_OOB         =$1;             // process out-of-band data
  MSG_PEEK        =$2;             // peek at incoming message
  MSG_DONTROUTE   =$4;             // send without using routing tables
  MSG_FULLREAD    =$8;             // send without using routing tables

  MSG_MAXIOVLEN   =16;

const
{ All Windows Sockets error constants are biased by WSABASEERR from the "normal" }

  WSABASEERR              = 10000;

{ Windows Sockets definitions of regular Microsoft C error constants }

  WSAEINTR                = (WSABASEERR+4);
  WSAEBADF                = (WSABASEERR+9);
  WSAEACCES               = (WSABASEERR+13);
  WSAEFAULT               = (WSABASEERR+14);
  WSAEINVAL               = (WSABASEERR+22);
  WSAEMFILE               = (WSABASEERR+24);

{ Windows Sockets definitions of regular Berkeley error constants }

{$IFNDEF LINUX}
  WSAEWOULDBLOCK          = (WSABASEERR+35);
  WSAEINPROGRESS          = (WSABASEERR+36);
  WSAEALREADY             = (WSABASEERR+37);
  WSAENOTSOCK             = (WSABASEERR+38);
  WSAEDESTADDRREQ         = (WSABASEERR+39);
  WSAEMSGSIZE             = (WSABASEERR+40);
  WSAEPROTOTYPE           = (WSABASEERR+41);
  WSAENOPROTOOPT          = (WSABASEERR+42);
  WSAEPROTONOSUPPORT      = (WSABASEERR+43);
  WSAESOCKTNOSUPPORT      = (WSABASEERR+44);
  WSAEOPNOTSUPP           = (WSABASEERR+45);
  WSAEPFNOSUPPORT         = (WSABASEERR+46);
  WSAEAFNOSUPPORT         = (WSABASEERR+47);
  WSAEADDRINUSE           = (WSABASEERR+48);
  WSAEADDRNOTAVAIL        = (WSABASEERR+49);
  WSAENETDOWN             = (WSABASEERR+50);
  WSAENETUNREACH          = (WSABASEERR+51);
  WSAENETRESET            = (WSABASEERR+52);
  WSAECONNABORTED         = (WSABASEERR+53);
  WSAECONNRESET           = (WSABASEERR+54);
  WSAENOBUFS              = (WSABASEERR+55);
  WSAEISCONN              = (WSABASEERR+56);
  WSAENOTCONN             = (WSABASEERR+57);
  WSAESHUTDOWN            = (WSABASEERR+58);
  WSAETOOMANYREFS         = (WSABASEERR+59);
  WSAETIMEDOUT            = (WSABASEERR+60);
  WSAECONNREFUSED         = (WSABASEERR+61);
  WSAELOOP                = (WSABASEERR+62);
  WSAENAMETOOLONG         = (WSABASEERR+63);
  WSAEHOSTDOWN            = (WSABASEERR+64);
  WSAEHOSTUNREACH         = (WSABASEERR+65);
  WSAENOTEMPTY            = (WSABASEERR+66);
  WSAEPROCLIM             = (WSABASEERR+67);
  WSAEUSERS               = (WSABASEERR+68);
  WSAEDQUOT               = (WSABASEERR+69);
  WSAESTALE               = (WSABASEERR+70);
  WSAEREMOTE              = (WSABASEERR+71);

  WSAEDISCON              = (WSABASEERR+101);
{$ENDIF}

{$IFDEF LINUX}
  WSAEWOULDBLOCK          = 11;
  WSAEINPROGRESS          = 115;
  WSAEALREADY             = 114;
  WSAENOTSOCK             = 88;
  WSAEDESTADDRREQ         = 89;
  WSAEMSGSIZE             = 90;
  WSAEPROTOTYPE           = 91;
  WSAENOPROTOOPT          = 92;
  WSAEPROTONOSUPPORT      = 93;
  WSAESOCKTNOSUPPORT      = 94;
  WSAEOPNOTSUPP           = 95;
  WSAEPFNOSUPPORT         = 96;
  WSAEAFNOSUPPORT         = 97;
  WSAEADDRINUSE           = 98;
  WSAEADDRNOTAVAIL        = 99;
  WSAENETDOWN             = 100;
  WSAENETUNREACH          = 101;
  WSAENETRESET            = 102;
  WSAECONNABORTED         = 103;
  WSAECONNRESET           = 104;
  WSAENOBUFS              = 105;
  WSAEISCONN              = 106;
  WSAENOTCONN             = 107;
  WSAESHUTDOWN            = 108;
  WSAETOOMANYREFS         = 109;
  WSAETIMEDOUT            = 110;
  WSAECONNREFUSED         = 111;
  WSAELOOP                = 40;
  WSAENAMETOOLONG         = 36;
  WSAEHOSTDOWN            = 112;
  WSAEHOSTUNREACH         = 113;
  WSAENOTEMPTY            = 39;
  WSAEPROCLIM             = 00;
  WSAEUSERS               = 87;
  WSAEDQUOT               = 122;
  WSAESTALE               = 116;
  WSAEREMOTE              = 66;
{$ENDIF}

{ Extended Windows Sockets error constant definitions }

  WSASYSNOTREADY          = (WSABASEERR+91);
  WSAVERNOTSUPPORTED      = (WSABASEERR+92);
  WSANOTINITIALISED       = (WSABASEERR+93);

{ Error return codes from gethostbyname() and gethostbyaddr()
  (when using the resolver). Note that these errors are
  retrieved via WSAGetLastError() and must therefore follow
  the rules for avoiding clashes with error numbers from
  specific implementations or language run-time systems.
  For this reason the codes are based at WSABASEERR+1001.
  Note also that [WSA]NO_ADDRESS is defined only for
  compatibility purposes. }

{ Authoritative Answer: Host not found }

  WSAHOST_NOT_FOUND       = (WSABASEERR+1001);
  HOST_NOT_FOUND          = WSAHOST_NOT_FOUND;

{ Non-Authoritative: Host not found, or SERVERFAIL }

  WSATRY_AGAIN            = (WSABASEERR+1002);
  TRY_AGAIN               = WSATRY_AGAIN;

{ Non recoverable errors, FORMERR, REFUSED, NOTIMP }

  WSANO_RECOVERY          = (WSABASEERR+1003);
  NO_RECOVERY             = WSANO_RECOVERY;

{ Valid name, no data record of requested type }

  WSANO_DATA              = (WSABASEERR+1004);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -