13 files changed:
{$include lcoreconfig.inc}\r
\r
uses\r
{$include lcoreconfig.inc}\r
\r
uses\r
sockets,\r
{$endif}\r
pgtypes;\r
sockets,\r
{$endif}\r
pgtypes;\r
\r
const\r
hexchars:array[0..15] of ansichar='0123456789abcdef';\r
\r
const\r
hexchars:array[0..15] of ansichar='0123456789abcdef';\r
AF_INET=2;\r
AF_INET6=23;\r
{$else}\r
AF_INET=2;\r
AF_INET6=23;\r
{$else}\r
type\r
{$ifdef ipv6}\r
\r
type\r
{$ifdef ipv6}\r
\r
{$define want_Tin6_addr}\r
{$endif}\r
{$ifdef ver1_0}\r
{$define want_Tin6_addr}\r
{$endif}\r
{$ifdef ver1_0}\r
TInetSockAddr = packed Record\r
family:Word;\r
port :Word;\r
TInetSockAddr = packed Record\r
family:Word;\r
port :Word;\r
uses\r
ltimevalstuff;\r
{$endif} \r
uses\r
ltimevalstuff;\r
{$endif} \r
function timestriso(i:tunixtimeint):string; // 2012-08-15 16:21:09\r
function timestrisoutc(i:float):string; // 2012-08-15T14:21:09.255553Z\r
\r
function timestriso(i:tunixtimeint):string; // 2012-08-15 16:21:09\r
function timestrisoutc(i:float):string; // 2012-08-15T14:21:09.255553Z\r
\r
function unixtimefloat_systemtime:float;\r
{$endif}\r
\r
function unixtimefloat_systemtime:float;\r
{$endif}\r
\r
function oletounix(t:tdatetime):tunixtimeint;\r
function unixtoole(i:float):tdatetime;\r
\r
function oletounix(t:tdatetime):tunixtimeint;\r
function unixtoole(i:float):tdatetime;\r
\r
function mmtimefloat:float;\r
function qpctimefloat:float;\r
{$endif}\r
\r
function mmtimefloat:float;\r
function qpctimefloat:float;\r
{$endif}\r
\r
procedure gettimeofday(var tv:ttimeval);\r
{$endif}\r
\r
procedure gettimeofday(var tv:ttimeval);\r
{$endif}\r
\r
\r
procedure init;\r
begin\r
\r
procedure init;\r
begin\r
- {$ifdef win32}timebeginperiod(1);{$endif} //ensure stable unchanging clock\r
+ {$ifdef mswindows}timebeginperiod(1);{$endif} //ensure stable unchanging clock\r
fillchar(mmtime_driftavg,sizeof(mmtime_driftavg),0);\r
settimebias := 0;\r
gettimezone;\r
fillchar(mmtime_driftavg,sizeof(mmtime_driftavg),0);\r
settimebias := 0;\r
gettimezone;\r
dnswin,\r
{$endif}\r
lsocket,lcore,\r
dnswin,\r
{$endif}\r
lsocket,lcore,\r
\r
dnsserverids : array[0..numsock-1] of integer;\r
startts:double;\r
\r
dnsserverids : array[0..numsock-1] of integer;\r
startts:double;\r
dwas : tdnswinasync;\r
{$endif}\r
\r
dwas : tdnswinasync;\r
{$endif}\r
\r
procedure asyncprocess(socketno:integer);\r
procedure receivehandler(sender:tobject;error:word);\r
function sendquery(socketno:integer;const packet:tdnspacket;len:integer):boolean;\r
procedure asyncprocess(socketno:integer);\r
procedure receivehandler(sender:tobject;error:word);\r
function sendquery(socketno:integer;const packet:tdnspacket;len:integer):boolean;\r
procedure winrequestdone(sender:tobject;error:word);\r
{$endif}\r
\r
procedure winrequestdone(sender:tobject;error:word);\r
{$endif}\r
\r
end;\r
destinations[socketno] := destination;\r
\r
end;\r
destinations[socketno] := destination;\r
\r
- {$ifdef ipv6}{$ifdef win32}\r
+ {$ifdef ipv6}{$ifdef mswindows}\r
if destinations[socketno].family = AF_INET6 then if (requestaf = useaf_default) then requestaf := useaf_preferv6;\r
{$endif}{$endif}\r
\r
if destinations[socketno].family = AF_INET6 then if (requestaf = useaf_default) then requestaf := useaf_preferv6;\r
{$endif}{$endif}\r
\r
\r
if overrideaf = useaf_default then begin\r
{$ifdef ipv6}\r
\r
if overrideaf = useaf_default then begin\r
{$ifdef ipv6}\r
- {$ifdef win32}if not (usewindns and (addr = '')) then{$endif}\r
+ {$ifdef mswindows}if not (usewindns and (addr = '')) then{$endif}\r
initpreferredmode;\r
{$endif}\r
requestaf := useaf;\r
initpreferredmode;\r
{$endif}\r
requestaf := useaf;\r
requestaf := overrideaf;\r
end;\r
\r
requestaf := overrideaf;\r
end;\r
\r
if usewindns and (addr = '') then begin\r
dwas := tdnswinasync.create;\r
dwas.onrequestdone := winrequestdone;\r
if usewindns and (addr = '') then begin\r
dwas := tdnswinasync.create;\r
dwas.onrequestdone := winrequestdone;\r
\r
procedure tdnsasync.reverselookup;\r
begin\r
\r
procedure tdnsasync.reverselookup;\r
begin\r
if usewindns and (addr = '') then begin\r
dwas := tdnswinasync.create;\r
dwas.onrequestdone := winrequestdone;\r
if usewindns and (addr = '') then begin\r
dwas := tdnswinasync.create;\r
dwas.onrequestdone := winrequestdone;\r
var\r
socketno : integer;\r
begin\r
var\r
socketno : integer;\r
begin\r
if assigned(dwas) then begin\r
dwas.release;\r
dwas := nil;\r
if assigned(dwas) then begin\r
dwas.release;\r
dwas := nil;\r
onrequestdone(self,0);\r
end;\r
\r
onrequestdone(self,0);\r
end;\r
\r
procedure tdnsasync.winrequestdone(sender:tobject;error:word);\r
\r
begin\r
procedure tdnsasync.winrequestdone(sender:tobject;error:word);\r
\r
begin\r
\r
uses binipstuff,classes,pgtypes,lcorernd;\r
\r
\r
uses binipstuff,classes,pgtypes,lcorernd;\r
\r
-var usewindns : boolean = {$ifdef win32}true{$else}false{$endif};\r
+var usewindns : boolean = {$ifdef mswindows}true{$else}false{$endif};\r
{hint to users of this unit that they should use windows dns instead.\r
May be disabled by applications if desired. (e.g. if setting a custom\r
dnsserverlist).\r
{hint to users of this unit that they should use windows dns instead.\r
May be disabled by applications if desired. (e.g. if setting a custom\r
dnsserverlist).\r
uses\r
dnscore,\r
binipstuff,\r
uses\r
dnscore,\r
binipstuff,\r
winsock,\r
windows,\r
{$else}\r
winsock,\r
windows,\r
{$else}\r
uses dnswin;\r
{$endif}\r
\r
\r
uses dnswin;\r
{$endif}\r
\r
\r
{$define syncdnscore}\r
{$endif}\r
\r
{$define syncdnscore}\r
{$endif}\r
\r
{$ifdef syncdnscore}\r
\r
\r
{$ifdef syncdnscore}\r
\r
\r
const\r
winsocket = 'wsock32.dll';\r
function sendto(s: TSocket; const Buf; len, flags: Integer; var addrto: TinetSockAddrV; tolen: Integer): Integer; stdcall; external winsocket name 'sendto';\r
const\r
winsocket = 'wsock32.dll';\r
function sendto(s: TSocket; const Buf; len, flags: Integer; var addrto: TinetSockAddrV; tolen: Integer): Integer; stdcall; external winsocket name 'sendto';\r
\r
\r
function getts:integer;\r
\r
\r
function getts:integer;\r
begin\r
result := GetTickCount and tsmask;\r
{$else}\r
begin\r
result := GetTickCount and tsmask;\r
{$else}\r
a,b:integer;\r
\r
Src : TInetSockAddrV;\r
a,b:integer;\r
\r
Src : TInetSockAddrV;\r
- Srcx : {$ifdef win32}sockaddr_in{$else}TInetSockAddrV{$endif} absolute Src;\r
+ Srcx : {$ifdef mswindows}sockaddr_in{$else}TInetSockAddrV{$endif} absolute Src;\r
SrcLen : Integer;\r
fromip:tbinip;\r
fromport:ansistring;\r
SrcLen : Integer;\r
fromip:tbinip;\r
fromport:ansistring;\r
makeinaddrv(biniptemp,inttostr( porttemp ),inaddrtemp);\r
\r
fd[a] := Socket(biniptemp.family,SOCK_DGRAM,0);\r
makeinaddrv(biniptemp,inttostr( porttemp ),inaddrtemp);\r
\r
fd[a] := Socket(biniptemp.family,SOCK_DGRAM,0);\r
- bindresult := {$ifdef win32}Not{$endif} Bind(fd[a],inAddrtemp,inaddrsize(inaddrtemp));\r
+ bindresult := {$ifdef mswindows}Not{$endif} Bind(fd[a],inAddrtemp,inaddrsize(inaddrtemp));\r
dec(retrycount);\r
until (retrycount <= 0) or (bindresult);\r
\r
If (not bindresult) Then begin\r
dec(retrycount);\r
until (retrycount <= 0) or (bindresult);\r
\r
If (not bindresult) Then begin\r
raise Exception.create('unable to bind '+inttostr(WSAGetLastError));\r
{$else}\r
raise Exception.create('unable to bind '+inttostr(socketError));\r
raise Exception.create('unable to bind '+inttostr(WSAGetLastError));\r
{$else}\r
raise Exception.create('unable to bind '+inttostr(socketError));\r
\r
ip := getcurrentsystemnameserverbin(id);\r
\r
\r
ip := getcurrentsystemnameserverbin(id);\r
\r
- {$ifdef ipv6}{$ifdef win32}\r
+ {$ifdef ipv6}{$ifdef mswindows}\r
if toaddr[socknum].family = AF_INET6 then if (useaf = 0) then useaf := useaf_preferv6;\r
{$endif}{$endif}\r
\r
if toaddr[socknum].family = AF_INET6 then if (useaf = 0) then useaf := useaf_preferv6;\r
{$endif}{$endif}\r
\r
exit; //it was an IP address, no need for dns\r
end;\r
\r
exit; //it was an IP address, no need for dns\r
end;\r
\r
if usewindns then begin\r
if (useaf = useaf_v4) then a := af_inet else if (useaf = useaf_v6) then a := af_inet6 else a := 0;\r
result := winforwardlookuplist(name,a,dummy);\r
if usewindns then begin\r
if (useaf = useaf_v4) then a := af_inet else if (useaf = useaf_v6) then a := af_inet6 else a := 0;\r
result := winforwardlookuplist(name,a,dummy);\r
numsockused:integer;\r
state:tdnsstatearr;\r
begin\r
numsockused:integer;\r
state:tdnsstatearr;\r
begin\r
if usewindns then begin\r
result := winreverselookup(ip,dummy);\r
exit;\r
if usewindns then begin\r
result := winreverselookup(ip,dummy);\r
exit;\r
var\r
wsadata : twsadata;\r
\r
var\r
wsadata : twsadata;\r
\r
{$ifdef fpc}\r
{$mode delphi}\r
{$endif}\r
{$ifdef fpc}\r
{$mode delphi}\r
{$endif}\r
{$define nosignal}\r
{$endif}\r
interface\r
uses\r
sysutils,\r
{$define nosignal}\r
{$endif}\r
interface\r
uses\r
sysutils,\r
{$ifdef VER1_0}\r
linux,\r
{$else}\r
{$ifdef VER1_0}\r
linux,\r
{$else}\r
\r
function RealSend(Data : Pointer; Len : Integer) : Integer; //added for bewarehttpd\r
\r
\r
function RealSend(Data : Pointer; Len : Integer) : Integer; //added for bewarehttpd\r
\r
- procedure myfdclose(fd : integer); virtual;{$ifdef win32}abstract;{$endif}\r
- function myfdwrite(fd: LongInt;const buf;size: LongInt):LongInt; virtual;{$ifdef win32}abstract;{$endif}\r
- function myfdread(fd: LongInt;var buf;size: LongInt):LongInt; virtual;{$ifdef win32}abstract;{$endif}\r
+ procedure myfdclose(fd : integer); virtual;{$ifdef mswindows}abstract;{$endif}\r
+ function myfdwrite(fd: LongInt;const buf;size: LongInt):LongInt; virtual;{$ifdef mswindows}abstract;{$endif}\r
+ function myfdread(fd: LongInt;var buf;size: LongInt):LongInt; virtual;{$ifdef mswindows}abstract;{$endif}\r
protected\r
procedure dupnowatch(invalue:longint);\r
end;\r
protected\r
procedure dupnowatch(invalue:longint);\r
end;\r
fontimer : tnotifyevent ;\r
fenabled : boolean ;\r
finterval : integer ; {miliseconds, default 1000}\r
fontimer : tnotifyevent ;\r
fenabled : boolean ;\r
finterval : integer ; {miliseconds, default 1000}\r
procedure resettimes;\r
{$endif}\r
// procedure setinitialevent(newvalue : boolean);\r
procedure resettimes;\r
{$endif}\r
// procedure setinitialevent(newvalue : boolean);\r
{$ifndef nosignal}\r
uses {sockets,}lloopback,lsignal;\r
{$endif}\r
{$ifndef nosignal}\r
uses {sockets,}lloopback,lsignal;\r
{$endif}\r
uses windows,winsock;\r
{$endif}\r
uses windows,winsock;\r
{$endif}\r
{$include unixstuff.inc}\r
{$endif}\r
\r
\r
{!!! added sleep call -beware}\r
procedure sleep(i:integer);\r
{$include unixstuff.inc}\r
{$endif}\r
\r
\r
{!!! added sleep call -beware}\r
procedure sleep(i:integer);\r
begin\r
windows.sleep(i);\r
{$else}\r
begin\r
windows.sleep(i);\r
{$else}\r
eventcore.wmasterclr(fdhandleout);//fd_clr(fdhandleout,fdswmaster);\r
\r
if closehandles then begin\r
eventcore.wmasterclr(fdhandleout);//fd_clr(fdhandleout,fdswmaster);\r
\r
if closehandles then begin\r
//anyone remember why this is here? --plugwash\r
fcntl(fdhandlein,F_SETFL,0);\r
{$endif}\r
myfdclose(fdhandlein);\r
if fdhandleout <> fdhandlein then begin\r
//anyone remember why this is here? --plugwash\r
fcntl(fdhandlein,F_SETFL,0);\r
{$endif}\r
myfdclose(fdhandlein);\r
if fdhandleout <> fdhandlein then begin\r
fcntl(fdhandleout,F_SETFL,0);\r
{$endif}\r
myfdclose(fdhandleout);\r
fcntl(fdhandleout,F_SETFL,0);\r
{$endif}\r
myfdclose(fdhandleout);\r
fdhandlein := invalue;\r
fdhandleout := invalue;\r
eventcore.setfdreverse(fdhandlein,self);\r
fdhandlein := invalue;\r
fdhandleout := invalue;\r
eventcore.setfdreverse(fdhandlein,self);\r
fcntl(fdhandlein,F_SETFL,OPEN_NONBLOCK);\r
{$endif}\r
state := wsconnected;\r
fcntl(fdhandlein,F_SETFL,OPEN_NONBLOCK);\r
{$endif}\r
state := wsconnected;\r
internalclose(0);\r
\r
end else begin\r
internalclose(0);\r
\r
end else begin\r
if getlasterror=WSAEWOULDBLOCK then begin\r
//the asynchronous nature of windows messages means we sometimes\r
//get here with the buffer full\r
if getlasterror=WSAEWOULDBLOCK then begin\r
//the asynchronous nature of windows messages means we sometimes\r
//get here with the buffer full\r
end else\r
{$endif}\r
begin\r
end else\r
{$endif}\r
begin\r
- internalclose({$ifdef win32}getlasterror{$else}linuxerror{$endif});\r
+ internalclose({$ifdef mswindows}getlasterror{$else}linuxerror{$endif});\r
\r
internalclose(0);\r
end else if (numread=-1) then begin\r
\r
internalclose(0);\r
end else if (numread=-1) then begin\r
//sometimes on windows we get stale messages due to the inherent delays\r
//in the windows message queue\r
if WSAGetLastError = wsaewouldblock then begin\r
//sometimes on windows we get stale messages due to the inherent delays\r
//in the windows message queue\r
if WSAGetLastError = wsaewouldblock then begin\r
{$endif}\r
begin\r
numread := 0;\r
{$endif}\r
begin\r
numread := 0;\r
- internalclose({$ifdef win32}wsagetlasterror{$else}linuxerror{$endif});\r
+ internalclose({$ifdef mswindows}wsagetlasterror{$else}linuxerror{$endif});\r
end;\r
end else if numread > 0 then recvq.add(@tempbuf,numread);\r
end;\r
end;\r
end else if numread > 0 then recvq.add(@tempbuf,numread);\r
end;\r
end;\r
\r
procedure tlasio.flush;\r
end;\r
\r
procedure tlasio.flush;\r
type fdset = tfdset;\r
{$endif}\r
var\r
type fdset = tfdset;\r
{$endif}\r
var\r
tlasio(sender).recvq.del(maxlongint);\r
end;\r
\r
tlasio(sender).recvq.del(maxlongint);\r
end;\r
\r
procedure tltimer.resettimes;\r
begin\r
gettimeofday(nextts);\r
procedure tltimer.resettimes;\r
begin\r
gettimeofday(nextts);\r
if assigned(timerwrapperinterface) then begin\r
timerwrapperinterface.setenabled(wrappedtimer,newvalue);\r
end else begin\r
if assigned(timerwrapperinterface) then begin\r
timerwrapperinterface.setenabled(wrappedtimer,newvalue);\r
end else begin\r
raise exception.create('non wrapper timers are not permitted on windows');\r
{$else}\r
resettimes;\r
raise exception.create('non wrapper timers are not permitted on windows');\r
{$else}\r
resettimes;\r
if assigned(timerwrapperinterface) then begin\r
timerwrapperinterface.setinterval(wrappedtimer,newvalue);\r
end else begin\r
if assigned(timerwrapperinterface) then begin\r
timerwrapperinterface.setinterval(wrappedtimer,newvalue);\r
end else begin\r
raise exception.create('non wrapper timers are not permitted on windows');\r
{$else}\r
resettimes;\r
raise exception.create('non wrapper timers are not permitted on windows');\r
{$else}\r
resettimes;\r
if (result > 0) and assigned(onsenddata) then onsenddata(self,result);\r
eventcore.wmasterset(fdhandleout);\r
end;\r
if (result > 0) and assigned(onsenddata) then onsenddata(self,result);\r
eventcore.wmasterset(fdhandleout);\r
end;\r
procedure tlasio.myfdclose(fd : integer);\r
begin\r
fdclose(fd);\r
procedure tlasio.myfdclose(fd : integer);\r
begin\r
fdclose(fd);\r
\r
function getsystemdnsservers:tbiniplist;\r
\r
\r
function getsystemdnsservers:tbiniplist;\r
\r
function gethostname:ansistring;\r
{$endif}\r
\r
function gethostname:ansistring;\r
{$endif}\r
\r
const\r
MAX_HOSTNAME_LEN = 132;\r
MAX_DOMAIN_NAME_LEN = 132;\r
const\r
MAX_HOSTNAME_LEN = 132;\r
MAX_DOMAIN_NAME_LEN = 132;\r
\r
function getsystemdnsservers:tbiniplist;\r
var\r
\r
function getsystemdnsservers:tbiniplist;\r
var\r
fixed_info : pfixed_info;\r
currentdnsserver : pip_addr_string;\r
{$else}\r
fixed_info : pfixed_info;\r
currentdnsserver : pip_addr_string;\r
{$else}\r
\r
result := biniplist_new;\r
\r
\r
result := biniplist_new;\r
\r
fixed_info := callgetnetworkparams;\r
if fixed_info = nil then exit;\r
\r
fixed_info := callgetnetworkparams;\r
if fixed_info = nil then exit;\r
\r
function gethostname:ansistring;\r
var\r
fixed_info : pfixed_info;\r
function gethostname:ansistring;\r
var\r
fixed_info : pfixed_info;\r
\r
{$ifndef nolcorernd}\r
uses\r
\r
{$ifndef nolcorernd}\r
uses\r
- {$ifdef win32}windows,activex,{$endif}\r
+ {$ifdef mswindows}windows,activex,{$endif}\r
{$ifdef unix}\r
{$ifdef ver1_0}\r
linux,\r
{$ifdef unix}\r
{$ifdef ver1_0}\r
linux,\r
pool:array[0..(pooldwords+seeddwords-1)] of wordtype;\r
reseedcountdown:integer;\r
\r
pool:array[0..(pooldwords+seeddwords-1)] of wordtype;\r
reseedcountdown:integer;\r
\r
function collect_seeding(var output;const bufsize:integer):integer;\r
var\r
l:packed record\r
function collect_seeding(var output;const bufsize:integer):integer;\r
var\r
l:packed record\r
uses\r
lcore,\r
lsocket,\r
uses\r
lcore,\r
lsocket,\r
lcorewsaasyncselect in 'lcorewsaasyncselect.pas',\r
{$else}\r
lcoreselect,\r
lcorewsaasyncselect in 'lcorewsaasyncselect.pas',\r
{$else}\r
lcoreselect,\r
dnssync\r
//we don't actually make any use of the units below in this app, we just\r
//include it to check if it compiles ok ;)\r
dnssync\r
//we don't actually make any use of the units below in this app, we just\r
//include it to check if it compiles ok ;)\r
,\r
{$ifndef nomessages}\r
lmessages,\r
,\r
{$ifndef nomessages}\r
lmessages,\r
unitfork\r
{$endif}\r
;\r
unitfork\r
{$endif}\r
;\r
{$R *.RES}\r
{$endif}\r
\r
{$R *.RES}\r
{$endif}\r
\r
interface\r
uses\r
sysutils,\r
interface\r
uses\r
sysutils,\r
windows,winsock,\r
{$else}\r
\r
windows,winsock,\r
{$else}\r
\r
\r
{public in tlasio, and can't be private in both places, so should be public here. \r
fixes delphi warning --beware}\r
\r
{public in tlasio, and can't be private in both places, so should be public here. \r
fixes delphi warning --beware}\r
procedure myfdclose(fd : integer); override;\r
function myfdwrite(fd: LongInt;const buf;size: LongInt):LongInt; override;\r
function myfdread(fd: LongInt;var buf;size: LongInt):LongInt; override;\r
procedure myfdclose(fd : integer); override;\r
function myfdwrite(fd: LongInt;const buf;size: LongInt):LongInt; override;\r
function myfdread(fd: LongInt;var buf;size: LongInt):LongInt; override;\r
//functions whose name clashes with them) by using sockets.* and but I can't do\r
//that anymore since in some cases connect is now provided by unixstuff.inc\r
//hence these wrapper functions --plugwash\r
//functions whose name clashes with them) by using sockets.* and but I can't do\r
//that anymore since in some cases connect is now provided by unixstuff.inc\r
//hence these wrapper functions --plugwash\r
function system_Connect(Sock: LongInt;const Addr;Addrlen: LongInt):Boolean;\r
begin\r
result := connect(sock,addr,addrlen);\r
function system_Connect(Sock: LongInt;const Addr;Addrlen: LongInt):Boolean;\r
begin\r
result := connect(sock,addr,addrlen);\r
//we want internalclose to act as if there was\r
fdhandlein := -2;\r
fdhandleout := -2;\r
//we want internalclose to act as if there was\r
fdhandlein := -2;\r
fdhandleout := -2;\r
- tltask.create(taskcallconnectionfailedhandler,self,{$ifdef win32}wsagetlasterror{$else}socketerror{$endif},0);\r
+ tltask.create(taskcallconnectionfailedhandler,self,{$ifdef mswindows}wsagetlasterror{$else}socketerror{$endif},0);\r
exit;\r
end;\r
try\r
dup(a);\r
bindsocket;\r
if dgram then begin\r
exit;\r
end;\r
try\r
dup(a);\r
bindsocket;\r
if dgram then begin\r
SetSocketOptions(fdhandleout, SOL_SOCKET, SO_BROADCAST, 'TRUE', Length('TRUE'));\r
{$else}\r
SetSockOpt(fdhandleout, SOL_SOCKET, SO_BROADCAST, 'TRUE', Length('TRUE'));\r
SetSocketOptions(fdhandleout, SOL_SOCKET, SO_BROADCAST, 'TRUE', Length('TRUE'));\r
{$else}\r
SetSockOpt(fdhandleout, SOL_SOCKET, SO_BROADCAST, 'TRUE', Length('TRUE'));\r
eventcore.wmasterclr(fdhandleout);\r
end else begin\r
state :=wsconnecting;\r
eventcore.wmasterclr(fdhandleout);\r
end else begin\r
state :=wsconnecting;\r
//writeln(inaddr.inaddr.port);\r
winsock.Connect(fdhandlein,winsock.psockaddr(@inADDR)^,getaddrsize);\r
{$else}\r
//writeln(inaddr.inaddr.port);\r
winsock.Connect(fdhandlein,winsock.psockaddr(@inADDR)^,getaddrsize);\r
{$else}\r
procedure tlsocket.bindsocket;\r
var\r
inAddrtemp:TInetSockAddrV;\r
procedure tlsocket.bindsocket;\r
var\r
inAddrtemp:TInetSockAddrV;\r
- inAddrtempx:{$ifdef win32}winsock.TSockaddr{$else}TInetSockAddrV{$endif} absolute inaddrtemp;\r
+ inAddrtempx:{$ifdef mswindows}winsock.TSockaddr{$else}TInetSockAddrV{$endif} absolute inaddrtemp;\r
inaddrtempsize:integer;\r
begin\r
try\r
inaddrtempsize:integer;\r
begin\r
try\r
{$ifdef ipv6}\r
isv6socket := (inaddrtemp.inaddr.family = AF_INET6);\r
{$endif}\r
{$ifdef ipv6}\r
isv6socket := (inaddrtemp.inaddr.family = AF_INET6);\r
{$endif}\r
- If Bind(fdhandlein,inaddrtempx,inaddrtempsize)<> {$ifdef win32}0{$else}true{$endif} Then begin\r
+ If Bind(fdhandlein,inaddrtempx,inaddrtempsize)<> {$ifdef mswindows}0{$else}true{$endif} Then begin\r
- lasterror := {$ifdef win32}getlasterror{$else}socketerror{$endif};\r
+ lasterror := {$ifdef mswindows}getlasterror{$else}socketerror{$endif};\r
raise ESocketException.create('unable to bind on address '+localaddr+'#'+localport+', error '+inttostr(lasterror));\r
end;\r
state := wsbound;\r
raise ESocketException.create('unable to bind on address '+localaddr+'#'+localport+', error '+inttostr(lasterror));\r
end;\r
state := wsbound;\r
\r
procedure tlsocket.listen;\r
var\r
\r
procedure tlsocket.listen;\r
var\r
yes,no:longint;\r
{$endif}\r
socktype:integer;\r
yes,no:longint;\r
{$endif}\r
socktype:integer;\r
- if fdhandlein = -1 then raise ESocketException.create('unable to create socket'{$ifdef win32}+' error='+inttostr(wsagetlasterror){$endif});\r
+ if fdhandlein = -1 then raise ESocketException.create('unable to create socket'{$ifdef mswindows}+' error='+inttostr(wsagetlasterror){$endif});\r
dupnowatch(fdhandlein); // sets up maxs and copies handle to fdhandleout among other things\r
//eventcore.setfdreverse(fdhandlein,self); //already taken care of by dup\r
state := wsclosed; // then set this back as it was an undesired side effect of dup\r
\r
try\r
dupnowatch(fdhandlein); // sets up maxs and copies handle to fdhandleout among other things\r
//eventcore.setfdreverse(fdhandlein,self); //already taken care of by dup\r
state := wsclosed; // then set this back as it was an undesired side effect of dup\r
\r
try\r
yes := $01010101; {Copied this from existing code. Value is empiric,\r
but works. (yes=true<>0) }\r
no := 0;\r
yes := $01010101; {Copied this from existing code. Value is empiric,\r
but works. (yes=true<>0) }\r
no := 0;\r
if not udp then begin\r
{!!! allow custom queue length? default 5}\r
if listenqueue = 0 then listenqueue := 5;\r
if not udp then begin\r
{!!! allow custom queue length? default 5}\r
if listenqueue = 0 then listenqueue := 5;\r
- If {$ifdef win32}winsock.listen{$else}system_listen{$endif}(fdhandlein,listenqueue)<>{$ifdef win32}0{$else}true{$endif} Then raise\r
+ If {$ifdef mswindows}winsock.listen{$else}system_listen{$endif}(fdhandlein,listenqueue)<>{$ifdef mswindows}0{$else}true{$endif} Then raise\r
esocketexception.create('unable to listen');\r
state := wsListening;\r
end else begin\r
esocketexception.create('unable to listen');\r
state := wsListening;\r
end else begin\r
SetSocketOptions(fdhandleout, SOL_SOCKET, SO_BROADCAST, 'TRUE', Length('TRUE'));\r
{$else}\r
SetSockOpt(fdhandleout, SOL_SOCKET, SO_BROADCAST, 'TRUE', Length('TRUE'));\r
SetSocketOptions(fdhandleout, SOL_SOCKET, SO_BROADCAST, 'TRUE', Length('TRUE'));\r
{$else}\r
SetSockOpt(fdhandleout, SOL_SOCKET, SO_BROADCAST, 'TRUE', Length('TRUE'));\r
{$endif}\r
\r
FromAddrSize := Sizeof(FromAddr);\r
{$endif}\r
\r
FromAddrSize := Sizeof(FromAddr);\r
result := winsock.accept(fdhandlein,@fromaddr,@fromaddrsize);\r
{$else}\r
result := system_accept(fdhandlein,fromaddr,fromaddrsize);\r
result := winsock.accept(fdhandlein,@fromaddr,@fromaddrsize);\r
{$else}\r
result := system_accept(fdhandlein,fromaddr,fromaddrsize);\r
eventcore.rmasterset(fdhandlein,true);\r
\r
if result = -1 then begin\r
eventcore.rmasterset(fdhandlein,true);\r
\r
if result = -1 then begin\r
- raise esocketexception.create('error '+inttostr({$ifdef win32}getlasterror{$else}socketerror{$endif})+' while accepting');\r
+ raise esocketexception.create('error '+inttostr({$ifdef mswindows}getlasterror{$else}socketerror{$endif})+' while accepting');\r
end;\r
if result > absoloutemaxs then begin\r
myfdclose(result);\r
end;\r
if result > absoloutemaxs then begin\r
myfdclose(result);\r
realdest : tinetsockaddrv;\r
biniptemp : tbinip;\r
{$endif}\r
realdest : tinetsockaddrv;\r
biniptemp : tbinip;\r
{$endif}\r
- destx : {$ifdef win32}winsock.pSockAddr{$else}pInetSockAddrV{$endif};\r
+ destx : {$ifdef mswindows}winsock.pSockAddr{$else}pInetSockAddrV{$endif};\r
\r
begin\r
{$ifdef secondlistener}\r
\r
begin\r
{$ifdef secondlistener}\r
biniptemp := inaddrvtobinip(dest);\r
converttov6(biniptemp);\r
destlen := makeinaddrv(biniptemp,inttostr(ntohs(dest.InAddr.port)),realdest);\r
biniptemp := inaddrvtobinip(dest);\r
converttov6(biniptemp);\r
destlen := makeinaddrv(biniptemp,inttostr(ntohs(dest.InAddr.port)),realdest);\r
- destx := {$ifdef win32}winsock.pSockAddr{$else}pInetSockAddrV{$endif}(@realdest)\r
+ destx := {$ifdef mswindows}winsock.pSockAddr{$else}pInetSockAddrV{$endif}(@realdest)\r
- destx := {$ifdef win32}winsock.pSockAddr{$else}pInetSockAddrV{$endif}(@dest)\r
+ destx := {$ifdef mswindows}winsock.pSockAddr{$else}pInetSockAddrV{$endif}(@dest)\r
- destx := {$ifdef win32}winsock.pSockAddr{$else}pInetSockAddrV{$endif}(@dest);\r
+ destx := {$ifdef mswindows}winsock.pSockAddr{$else}pInetSockAddrV{$endif}(@dest);\r
- result := {$ifdef win32}winsock.sendto{$else}system_sendto{$endif}(self.fdhandleout,data^,len,0,destx^,destlen);\r
+ result := {$ifdef mswindows}winsock.sendto{$else}system_sendto{$endif}(self.fdhandleout,data^,len,0,destx^,destlen);\r
var\r
tempsrc:TInetSockAddrV;\r
tempsrclen:integer;\r
var\r
tempsrc:TInetSockAddrV;\r
tempsrclen:integer;\r
- srcx : {$ifdef win32}winsock.TSockAddr{$else}TInetSockAddrV{$endif} absolute tempsrc;\r
+ srcx : {$ifdef mswindows}winsock.TSockAddr{$else}TInetSockAddrV{$endif} absolute tempsrc;\r
biniptemp:tbinip;\r
begin\r
{$ifdef secondlistener}\r
biniptemp:tbinip;\r
begin\r
{$ifdef secondlistener}\r
//connectread := true;\r
recvq.add(@tempbuf,numread);\r
end else begin\r
//connectread := true;\r
recvq.add(@tempbuf,numread);\r
end else begin\r
- connectionfailedhandler({$ifdef win32}wsagetlasterror{$else}linuxerror{$endif});\r
+ connectionfailedhandler({$ifdef mswindows}wsagetlasterror{$else}linuxerror{$endif});\r
exit;\r
end;\r
// if things went well here we are now in the state wsconnected with data sitting in our receive buffer\r
exit;\r
end;\r
// if things went well here we are now in the state wsconnected with data sitting in our receive buffer\r
\r
function tlsocket.getpeername(var addr:tsockaddrin;addrlen:integer):integer;\r
var\r
\r
function tlsocket.getpeername(var addr:tsockaddrin;addrlen:integer):integer;\r
var\r
- addrx : {$ifdef win32}winsock.tsockaddr{$else}tsockaddrin{$endif} absolute addr;\r
+ addrx : {$ifdef mswindows}winsock.tsockaddr{$else}tsockaddrin{$endif} absolute addr;\r
- result := {$ifdef win32}winsock.getpeername{$else}system_getpeername{$endif}(self.fdhandlein,addrx,addrlen);\r
+ result := {$ifdef mswindows}winsock.getpeername{$else}system_getpeername{$endif}(self.fdhandlein,addrx,addrlen);\r
end;\r
\r
procedure tlsocket.getxaddrbin(var binip:tbinip);\r
end;\r
\r
procedure tlsocket.getxaddrbin(var binip:tbinip);\r
i := sizeof(addr);\r
fillchar(addr,sizeof(addr),0);\r
\r
i := sizeof(addr);\r
fillchar(addr,sizeof(addr),0);\r
\r
winsock.getsockname(self.fdhandlein,psockaddr(@addr)^,i);\r
{$else}\r
getsocketname(self.fdhandlein,addr,i);\r
winsock.getsockname(self.fdhandlein,psockaddr(@addr)^,i);\r
{$else}\r
getsocketname(self.fdhandlein,addr,i);\r
begin\r
i := sizeof(addr);\r
fillchar(addr,sizeof(addr),0);\r
begin\r
i := sizeof(addr);\r
fillchar(addr,sizeof(addr),0);\r
winsock.getpeername(self.fdhandlein,psockaddr(@addr)^,i);\r
{$else}\r
system_getpeername(self.fdhandlein,addr,i);\r
winsock.getpeername(self.fdhandlein,psockaddr(@addr)^,i);\r
{$else}\r
system_getpeername(self.fdhandlein,addr,i);\r
i:integer;\r
begin\r
i := sizeof(addr);\r
i:integer;\r
begin\r
i := sizeof(addr);\r
winsock.getsockname(self.fdhandlein,psockaddrin(@addr)^,i);\r
\r
{$else}\r
winsock.getsockname(self.fdhandlein,psockaddrin(@addr)^,i);\r
\r
{$else}\r
i:integer;\r
begin\r
i := sizeof(addr);\r
i:integer;\r
begin\r
i := sizeof(addr);\r
winsock.getpeername(self.fdhandlein,psockaddrin(@addr)^,i);\r
\r
{$else}\r
winsock.getpeername(self.fdhandlein,psockaddrin(@addr)^,i);\r
\r
{$else}\r
result := inttostr(htons(addr.InAddr.port));\r
end;\r
\r
result := inttostr(htons(addr.InAddr.port));\r
end;\r
\r
procedure tlsocket.myfdclose(fd : integer);\r
begin\r
closesocket(fd);\r
procedure tlsocket.myfdclose(fd : integer);\r
begin\r
closesocket(fd);\r
unit ltimevalstuff;\r
interface\r
\r
unit ltimevalstuff;\r
interface\r
\r
type\r
ttimeval = record\r
tv_sec : longint; \r
type\r
ttimeval = record\r
tv_sec : longint; \r
//make things a little easier to test in the delphi GUI\r
readln;\r
{$endif}\r
//make things a little easier to test in the delphi GUI\r
readln;\r
{$endif}\r
windows,messages,wmessages,\r
{$else}\r
lmessages,\r
windows,messages,wmessages,\r
{$else}\r
lmessages,\r
function killtimer(id:taddrint):boolean;\r
procedure postmessage(msg,wparam,lparam:taddrint);\r
procedure messageloop;\r
function killtimer(id:taddrint):boolean;\r
procedure postmessage(msg,wparam,lparam:taddrint);\r
procedure messageloop;\r
procedure processmessages; virtual;\r
function processmessage:boolean;\r
{$endif} \r
procedure processmessages; virtual;\r
function processmessage:boolean;\r
{$endif} \r