interface\r
uses\r
sysutils,\r
- {$ifdef win32}\r
+ {$ifdef mswindows}\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
- {$ifdef win32}\r
+ {$ifdef mswindows}\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
-{$ifndef win32}\r
+{$ifndef mswindows}\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
- 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
- {$ifndef win32}\r
+ {$ifndef mswindows}\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
- {$ifdef win32}\r
+ {$ifdef mswindows}\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
- 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
{$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
state := wsclosed;\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
\r
procedure tlsocket.listen;\r
var\r
- {$ifndef win32}\r
+ {$ifndef mswindows}\r
yes,no:longint;\r
{$endif}\r
socktype:integer;\r
if (addr = '::') and (origaddr = '') and (fdhandlein < 0) then begin\r
{writeln('failed to create an IPV6 socket with error ',socketerror,'. trying to create an IPV4 one instead');}\r
addr := '0.0.0.0';\r
+ biniptemp := ipstrtobinf(addr);\r
fdhandlein := socket(PF_INET,socktype,0);\r
end;\r
{$endif}\r
\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
- {$ifndef win32}\r
+ {$ifndef mswindows}\r
yes := $01010101; {Copied this from existing code. Value is empiric,\r
but works. (yes=true<>0) }\r
no := 0;\r
\r
end;\r
end;\r
+ {$else}\r
+ SetSockOpt(fdhandlein, SOL_SOCKET, SO_REUSEADDR, 'TRUE', Length('TRUE'));\r
+\r
{$endif}\r
localaddr := addr;\r
localport := port;\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
- {$ifndef win32}\r
+ {$ifndef mswindows}\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
- {$ifdef win32}\r
+ {$ifdef mswindows}\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
- 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
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
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
end else begin\r
- destx := {$ifdef win32}winsock.pSockAddr{$else}pInetSockAddrV{$endif}(@dest)\r
+ destx := {$ifdef mswindows}winsock.pSockAddr{$else}pInetSockAddrV{$endif}(@dest)\r
end;\r
{$else}\r
- destx := {$ifdef win32}winsock.pSockAddr{$else}pInetSockAddrV{$endif}(@dest)\r
+ destx := {$ifdef mswindows}winsock.pSockAddr{$else}pInetSockAddrV{$endif}(@dest);\r
{$endif}\r
\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
end;\r
\r
\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
//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
\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
begin\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
i := sizeof(addr);\r
fillchar(addr,sizeof(addr),0);\r
\r
- {$ifdef win32}\r
+ {$ifdef mswindows}\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
- {$ifdef win32}\r
+ {$ifdef mswindows}\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
- {$ifdef win32}\r
+ {$ifdef mswindows}\r
winsock.getsockname(self.fdhandlein,psockaddrin(@addr)^,i);\r
\r
{$else}\r
i:integer;\r
begin\r
i := sizeof(addr);\r
- {$ifdef win32}\r
+ {$ifdef mswindows}\r
winsock.getpeername(self.fdhandlein,psockaddrin(@addr)^,i);\r
\r
{$else}\r
result := inttostr(htons(addr.InAddr.port));\r
end;\r
\r
-{$ifdef win32}\r
+{$ifdef mswindows}\r
procedure tlsocket.myfdclose(fd : integer);\r
begin\r
closesocket(fd);\r