/[lcore]/trunk/unixstuff.inc
ViewVC logotype

Contents of /trunk/unixstuff.inc

Parent Directory Parent Directory | Revision Log Revision Log


Revision 71 - (show annotations)
Wed Feb 10 03:34:48 2010 UTC (10 years, 3 months ago) by beware
File size: 4459 byte(s)
getsockname fixes. getXaddr was returning peer addr
1 {$ifdef UNIX}
2 {$macro on}
3 {$ifdef VER1_0}
4 {$define tv_sec := sec}
5 {$define tv_usec := usec}
6 function dup(const original:integer):integer;inline;
7 begin
8 linux.dup(original,result);
9 end;
10 {$define gettimeofdaysec := gettimeofday}
11 const
12 IPPROTO_UDP=17;
13 IPPROTO_ICMP=1;
14 function ntohs(invalue:word):word;inline;
15 var
16 invaluebytes : array[0..1] of byte absolute invalue;
17 resultbytes : array[0..1] of byte absolute result;
18 begin
19 {$ifdef endian_little}
20 resultbytes[0] := invaluebytes[1];
21 resultbytes[1] := invaluebytes[0];
22 {$else}
23 result := invalue;
24 {$endif}
25 end;
26 {$else}
27
28 {$define sigprocmask := fpsigprocmask}
29 {$define sigaction := fpsigaction}
30 {$define fdclose := fpclose}
31 {$define fcntl := fpfcntl}
32 {$define fdwrite := fpwrite}
33 {$define fdread := fpread}
34 {$define fdopen := fpopen}
35 {$define select := fpselect}
36 {$define linuxerror := fpgeterrno}
37 {$define fork := fpfork}
38 {$define getpid := fpgetpid}
39 {$define getenv := fpgetenv}
40 {$define chmod := fpchmod}
41 {$define dup2 := fpdup2}
42 {$ifndef ver1_9_2}
43 {$define flock := fpflock}
44 {$ifndef ver1_9_4}
45 procedure Execl(Todo:string);inline;
46 var
47 p : ppchar;
48 begin
49 p := unixutil.StringToPPChar(Todo,1);
50 if (p=nil) or (p^=nil) then exit;
51 fpexecv(p^,p);
52 end;
53 function SendTo(Sock: LongInt; const Buf;BufLen: LongInt;Flags: LongInt;var Addr;AddrLen: LongInt):LongInt;
54 begin
55 result := fpsendto(sock,@buf,buflen,flags,@addr,addrlen);
56 end;
57 function RecvFrom(Sock: LongInt;var Buf;Buflen: LongInt;Flags: LongInt;var Addr;var addrlen: Longint):LongInt;
58 begin
59 result := fprecvfrom(sock,@buf,buflen,flags,@addr,@addrlen);
60 end;
61 {$define socket := fpsocket}
62 function Bind(Sock: LongInt;const Addr;AddrLen: LongInt):Boolean;
63 begin
64 result := fpbind(sock,@addr,addrlen) = 0;
65 end;
66 function SetSocketOptions(Sock: LongInt;Level: LongInt;OptName: LongInt;const OptVal;optlen: LongInt):LongInt;
67 begin
68 result := fpsetsockopt(sock,level,optname,@optval,optlen);
69 end;
70 function Connect(Sock: LongInt;const Addr;Addrlen: LongInt):Boolean;
71 begin
72 result := fpconnect(sock,@addr,addrlen) >= 0;
73 end;
74 function listen(Sock: LongInt;MaxConnect: LongInt):Boolean;
75 begin
76 result := fplisten(sock,maxconnect) = 0;
77 end;
78 function GetPeerName(Sock: LongInt; var Addr;var Addrlen: LongInt):LongInt;
79 begin
80 result := fpgetpeername(sock,@addr,@addrlen);
81 end;
82 function GetSocketName(Sock: LongInt; var Addr;var Addrlen: LongInt):LongInt;
83 begin
84 result := fpgetsockname(sock,@addr,@addrlen);
85 end;
86 function Accept(Sock: LongInt; var Addr; var Addrlen: LongInt):LongInt;
87 begin
88 result := fpaccept(sock,@addr,@addrlen);
89 end;
90 {$endif}
91 {$endif}
92 {$ifdef ver2_0}
93 const
94 IPPROTO_UDP=17;
95 IPPROTO_ICMP=1;
96 {$endif}
97 {$ifdef ver1_9}
98 const
99 IPPROTO_UDP=17;
100 IPPROTO_ICMP=1;
101 function ntohs(invalue:word):word;inline;
102 var
103 invaluebytes : array[0..1] of byte absolute invalue;
104 resultbytes : array[0..1] of byte absolute result;
105 begin
106 {$ifdef endian_little}
107 resultbytes[0] := invaluebytes[1];
108 resultbytes[1] := invaluebytes[0];
109 {$else}
110 result := invalue;
111 {$endif}
112 end;
113 {$endif}
114 procedure gettimeofday(var tv:ttimeval);inline;
115 begin
116 fpgettimeofday(@tv,nil);
117 end;
118 function gettimeofdaysec : longint;
119 var
120 tv:ttimeval;
121 begin
122 gettimeofday(tv);
123 result := tv.tv_sec;
124 end;
125
126 //a function is used here rather than a define to prevent issues with tlasio.dup
127 function dup(const original:integer):integer;inline;
128 begin
129 result := fpdup(original);
130 end;
131 function octal(invalue:longint):longint;
132 var
133 a : integer;
134 i : integer;
135 begin
136 i := 0;
137 result := 0;
138 while invalue <> 0 do begin
139 a := invalue mod 10;
140 result := result + (a shl (i*3));
141
142 invalue := invalue div 10;
143 inc(i);
144 end;
145 end;
146 const
147 sys_eintr=esyseintr;
148
149 {$endif}
150 {$endif}

Properties

Name Value
svn:eol-style CRLF
svn:executable

No admin address has been configured">No admin address has been configured
ViewVC Help
Powered by ViewVC 1.1.22