/[lcore]/trunk/lsocket.pas
ViewVC logotype

Diff of /trunk/lsocket.pas

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 59 by plugwash, Mon Apr 13 02:44:32 2009 UTC revision 60 by plugwash, Thu Nov 12 20:47:41 2009 UTC
# Line 160  Line 160 
160    result := inaddrsize(inaddr);    result := inaddrsize(inaddr);
161  end;  end;
162    
163    //I used to use the system versions of these from within lsocket (which has
164    //functions whose name clashes with them) by using sockets.* and but I can't do
165    //that anymore since in some cases connect is now provided by unixstuff.inc
166    //hence these wrapper functions --plugwash
167    {$ifndef win32}
168      function system_Connect(Sock: LongInt;const Addr;Addrlen: LongInt):Boolean;
169      begin
170        result := connect(sock,addr,addrlen);
171      end;
172      function system_SendTo(Sock: LongInt; const Buf;BufLen: LongInt;Flags: LongInt;var Addr;AddrLen: LongInt):LongInt;
173      begin
174        result := sendto(sock,buf,buflen,flags,addr,addrlen);
175      end;
176      function system_getpeername(Sock: LongInt;var Addr;var Addrlen: LongInt):LongInt;
177      begin
178        result := getpeername(sock,addr,addrlen);
179      end;
180      function system_listen(Sock: LongInt; MaxConnect: LongInt):Boolean;
181      begin
182        result := listen(sock,maxconnect);
183      end;
184      function system_Accept(Sock: LongInt;var Addr;var Addrlen: LongInt):LongInt;
185      begin
186        result := accept(sock,addr,addrlen);
187      end;
188    {$endif}
189    
190  procedure tlsocket.realconnect;  procedure tlsocket.realconnect;
191  var  var
# Line 220  Line 246 
246          //writeln(inaddr.inaddr.port);          //writeln(inaddr.inaddr.port);
247          winsock.Connect(fdhandlein,winsock.psockaddr(@inADDR)^,getaddrsize);          winsock.Connect(fdhandlein,winsock.psockaddr(@inADDR)^,getaddrsize);
248        {$else}        {$else}
249          sockets.Connect(fdhandlein,inADDR,getaddrsize);          system_Connect(fdhandlein,inADDR,getaddrsize);
250        {$endif}        {$endif}
251        eventcore.rmasterset(fdhandlein,false);        eventcore.rmasterset(fdhandlein,false);
252        eventcore.wmasterset(fdhandleout);        eventcore.wmasterset(fdhandleout);
# Line 245  Line 271 
271    realconnect;    realconnect;
272  end;  end;
273    
274    
275    
276    
277  procedure tlsocket.connect;  procedure tlsocket.connect;
278  var  var
279    a:integer;    a:integer;
# Line 391  Line 420 
420      if not udp then begin      if not udp then begin
421        {!!! allow custom queue length? default 5}        {!!! allow custom queue length? default 5}
422        if listenqueue = 0 then listenqueue := 5;        if listenqueue = 0 then listenqueue := 5;
423        If {$ifdef win32}winsock{$else}sockets{$endif}.Listen(fdhandlein,listenqueue)<>{$ifdef win32}0{$else}true{$endif} Then raise        If {$ifdef win32}winsock.listen{$else}system_listen{$endif}(fdhandlein,listenqueue)<>{$ifdef win32}0{$else}true{$endif} Then raise
424  esocketexception.create('unable to listen');  esocketexception.create('unable to listen');
425        state := wsListening;        state := wsListening;
426      end else begin      end else begin
# Line 479  Line 508 
508    {$ifdef win32}    {$ifdef win32}
509      result := winsock.accept(fdhandlein,@fromaddr,@fromaddrsize);      result := winsock.accept(fdhandlein,@fromaddr,@fromaddrsize);
510    {$else}    {$else}
511      result := sockets.accept(fdhandlein,fromaddr,fromaddrsize);      result := system_accept(fdhandlein,fromaddr,fromaddrsize);
512    {$endif}    {$endif}
513    //now we have accepted one request start monitoring for more again    //now we have accepted one request start monitoring for more again
514    eventcore.rmasterset(fdhandlein,true);    eventcore.rmasterset(fdhandlein,true);
# Line 495  Line 524 
524    end;    end;
525  end;  end;
526    
527    
528  function tlsocket.sendto(dest:TInetSockAddrV;destlen:integer;data:pointer;len:integer):integer;  function tlsocket.sendto(dest:TInetSockAddrV;destlen:integer;data:pointer;len:integer):integer;
529  var  var
530    destx : {$ifdef win32}winsock.TSockAddr{$else}TInetSockAddrV{$endif} absolute dest;    destx : {$ifdef win32}winsock.TSockAddr{$else}TInetSockAddrV{$endif} absolute dest;
# Line 505  Line 535 
535      exit;      exit;
536    end;    end;
537    {$endif}    {$endif}
538    result := {$ifdef win32}winsock{$else}sockets{$endif}.sendto(self.fdhandleout,data^,len,0,destx,destlen);    result := {$ifdef win32}winsock.sendto{$else}system_sendto{$endif}(self.fdhandleout,data^,len,0,destx,destlen);
539  end;  end;
540    
541    
542  function tlsocket.receivefrom(data:pointer;len:integer;var src:TInetSockAddrV;var srclen:integer):integer;  function tlsocket.receivefrom(data:pointer;len:integer;var src:TInetSockAddrV;var srclen:integer):integer;
543  var  var
544    tempsrc:TInetSockAddrV;    tempsrc:TInetSockAddrV;
# Line 523  Line 554 
554    end;    end;
555    {$endif}    {$endif}
556    tempsrclen := sizeof(tempsrc);    tempsrclen := sizeof(tempsrc);
557    result := {$ifdef win32}winsock{$else}sockets{$endif}.recvfrom(self.fdhandlein,data^,len,0,srcx,tempsrclen);    result := recvfrom(self.fdhandlein,data^,len,0,srcx,tempsrclen);
558    
559    {$ifdef ipv6}    {$ifdef ipv6}
560    biniptemp := inaddrvtobinip(tempsrc);    biniptemp := inaddrvtobinip(tempsrc);
# Line 636  Line 667 
667  end;  end;
668    
669    
670    
671  function tlsocket.getpeername(var addr:tsockaddrin;addrlen:integer):integer;  function tlsocket.getpeername(var addr:tsockaddrin;addrlen:integer):integer;
672  var  var
673    addrx : {$ifdef win32}winsock.tsockaddr{$else}tsockaddrin{$endif} absolute addr;    addrx : {$ifdef win32}winsock.tsockaddr{$else}tsockaddrin{$endif} absolute addr;
674  begin  begin
675    result := {$ifdef win32}winsock{$else}sockets{$endif}.getpeername(self.fdhandlein,addrx,addrlen);    result := {$ifdef win32}winsock.getpeername{$else}system_getpeername{$endif}(self.fdhandlein,addrx,addrlen);
676  end;  end;
677    
678  procedure tlsocket.getxaddrbin(var binip:tbinip);  procedure tlsocket.getxaddrbin(var binip:tbinip);
# Line 654  Line 686 
686    {$ifdef win32}    {$ifdef win32}
687      winsock.getsockname(self.fdhandlein,psockaddr(@addr)^,i);      winsock.getsockname(self.fdhandlein,psockaddr(@addr)^,i);
688    {$else}    {$else}
689      sockets.getsocketname(self.fdhandlein,addr,i);      getsocketname(self.fdhandlein,addr,i);
690    {$endif}    {$endif}
691    binip := inaddrvtobinip(addr);    binip := inaddrvtobinip(addr);
692    converttov4(binip);    converttov4(binip);
# Line 670  Line 702 
702    {$ifdef win32}    {$ifdef win32}
703      winsock.getpeername(self.fdhandlein,psockaddr(@addr)^,i);      winsock.getpeername(self.fdhandlein,psockaddr(@addr)^,i);
704    {$else}    {$else}
705      sockets.getpeername(self.fdhandlein,addr,i);      system_getpeername(self.fdhandlein,addr,i);
706    {$endif}    {$endif}
707    
708    binip := inaddrvtobinip(addr);    binip := inaddrvtobinip(addr);
# Line 705  Line 737 
737      winsock.getsockname(self.fdhandlein,psockaddrin(@addr)^,i);      winsock.getsockname(self.fdhandlein,psockaddrin(@addr)^,i);
738    
739    {$else}    {$else}
740      sockets.getsocketname(self.fdhandlein,addr,i);      getsocketname(self.fdhandlein,addr,i);
741    
742    {$endif}    {$endif}
743    result := inttostr(htons(addr.InAddr.port));    result := inttostr(htons(addr.InAddr.port));
# Line 721  Line 753 
753      winsock.getpeername(self.fdhandlein,psockaddrin(@addr)^,i);      winsock.getpeername(self.fdhandlein,psockaddrin(@addr)^,i);
754    
755    {$else}    {$else}
756      sockets.getpeername(self.fdhandlein,addr,i);      system_getpeername(self.fdhandlein,addr,i);
757    
758    {$endif}    {$endif}
759    result := inttostr(htons(addr.InAddr.port));    result := inttostr(htons(addr.InAddr.port));

Legend:
Removed from v.59  
changed lines
  Added in v.60

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