* clean for non-unix, non-windows platforms

git-svn-id: trunk@5309 -
This commit is contained in:
Almindor 2006-11-10 16:34:04 +00:00
parent 84d5552deb
commit b922783481
6 changed files with 83 additions and 26 deletions

View File

@ -233,7 +233,7 @@ end;
function TClient.UserString: string; function TClient.UserString: string;
begin begin
{$ifdef win32} {$ifdef WINDOWS}
Result:='USERNAME'; Result:='USERNAME';
{$else} {$else}
Result:='USER'; Result:='USER';

View File

@ -27,7 +27,7 @@ program fphttpd;
uses uses
SysUtils, Classes, lNet, SysUtils, Classes, lNet,
{$ifndef WINDOWS} {$ifdef UNIX}
BaseUnix, Errors, BaseUnix, Errors,
{$endif} {$endif}
lhttp, lwebserver, lHTTPSettings, lSpawnFCGI; lhttp, lwebserver, lHTTPSettings, lSpawnFCGI;
@ -98,7 +98,7 @@ end;
procedure HandleSignals; procedure HandleSignals;
begin begin
{$ifndef WINDOWS} {$ifdef UNIX}
FpSignal(SIGTERM, @HandleTermSignal); FpSignal(SIGTERM, @HandleTermSignal);
FpSignal(SIGINT, @HandleTermSignal); FpSignal(SIGINT, @HandleTermSignal);
FpSignal(SIGHUP, signalhandler(SIG_IGN)); FpSignal(SIGHUP, signalhandler(SIG_IGN));
@ -107,7 +107,7 @@ begin
end; end;
function Daemonize: Integer; function Daemonize: Integer;
{$ifndef WINDOWS} {$ifdef UNIX}
var var
PID: TPid; PID: TPid;
begin begin

View File

@ -36,7 +36,27 @@ const
SOL_SOCKET = $ffff; SOL_SOCKET = $ffff;
LMSG = 0; LMSG = 0;
SOCKET_ERROR = WinSock2.SOCKET_ERROR; SOCKET_ERROR = WinSock2.SOCKET_ERROR;
{$ELSE} {$ENDIF}
{$IFDEF OS2}
SOL_SOCKET = WinSock.SOL_SOCKET;
LMSG = 0;
SOCKET_ERROR = WinSock.SOCKET_ERROR;
{$ENDIF}
{$IFDEF NETWARE}
SOL_SOCKET = WinSock.SOL_SOCKET;
LMSG = 0;
SOCKET_ERROR = WinSock.SOCKET_ERROR;
{$ENDIF}
{$IFDEF NETWLIBC}
SOL_SOCKET = WinSock.SOL_SOCKET;
LMSG = 0;
SOCKET_ERROR = WinSock.SOCKET_ERROR;
{$ENDIF}
{$IFDEF UNIX}
INVALID_SOCKET = -1; INVALID_SOCKET = -1;
SOCKET_ERROR = -1; SOCKET_ERROR = -1;
{$IFDEF LINUX} // TODO: fix this crap, some don't even have MSD_NOSIGNAL {$IFDEF LINUX} // TODO: fix this crap, some don't even have MSD_NOSIGNAL
@ -49,17 +69,13 @@ const
LDEFAULT_BACKLOG = 5; LDEFAULT_BACKLOG = 5;
BUFFER_SIZE = 65536; BUFFER_SIZE = 65536;
{$IFDEF WINDOWS} {$IFNDEF UNIX}
type type
TInetSockAddr = TSockAddrin; TInetSockAddr = TSockAddrin;
{$ENDIF} {$ENDIF}
{ Base functions } { Base functions }
function StrToHostAddr(const IP: string): Cardinal; inline; {$IFNDEF UNIX}
function HostAddrToStr(const Entry: Cardinal): string; inline;
function StrToNetAddr(const IP: string): Cardinal; inline;
function NetAddrToStr(const Entry: Cardinal): string; inline;
{$IFDEF WINDOWS}
function fpSelect(const nfds: Integer; const readfds, writefds, exceptfds: PFDSet; function fpSelect(const nfds: Integer; const readfds, writefds, exceptfds: PFDSet;
const timeout: PTimeVal): Integer; inline; const timeout: PTimeVal): Integer; inline;
function fpFD_ISSET(const Socket: Integer; var FDSet: TFDSet): Integer; inline; function fpFD_ISSET(const Socket: Integer; var FDSet: TFDSet): Integer; inline;
@ -77,10 +93,16 @@ type
function IsBlockError(const anError: Integer): Boolean; inline; function IsBlockError(const anError: Integer): Boolean; inline;
function StrToHostAddr(const IP: string): Cardinal; inline;
function HostAddrToStr(const Entry: Cardinal): string; inline;
function StrToNetAddr(const IP: string): Cardinal; inline;
function NetAddrToStr(const Entry: Cardinal): string; inline;
implementation implementation
{$IFDEF WINDOWS} {$IFNDEF UNIX}
{$IFDEF WINDOWS}
uses uses
Windows; Windows;
@ -109,6 +131,15 @@ begin
Result:=Tmp; Result:=Tmp;
end; end;
{$ELSE}
function LStrError(const Ernum: Longint; const UseUTF8: Boolean = False): string;
begin
Result:=IntToStr(Ernum); // TODO: fix for non-windows winsock users
end;
{$ENDIF}
function LSocketError: Longint; function LSocketError: Longint;
begin begin
Result:=WSAGetLastError; Result:=WSAGetLastError;
@ -187,7 +218,7 @@ begin
end; end;
{$ELSE} {$ELSE}
// unix
uses uses
Errors; Errors;
@ -253,14 +284,9 @@ end;
{$ENDIF} {$ENDIF}
function NetAddrToStr(const Entry: Cardinal): string; inline; function StrToHostAddr(const IP: string): Cardinal; inline;
begin begin
Result:=Sockets.NetAddrToStr(in_addr(Entry)); Result:=Cardinal(Sockets.StrToHostAddr(IP));
end;
function StrToNetAddr(const IP: string): Cardinal; inline;
begin
Result:=Cardinal(Sockets.StrToNetAddr(IP));
end; end;
function HostAddrToStr(const Entry: Cardinal): string; inline; function HostAddrToStr(const Entry: Cardinal): string; inline;
@ -268,9 +294,14 @@ begin
Result:=Sockets.HostAddrToStr(in_addr(Entry)); Result:=Sockets.HostAddrToStr(in_addr(Entry));
end; end;
function StrToHostAddr(const IP: string): Cardinal; inline; function StrToNetAddr(const IP: string): Cardinal; inline;
begin begin
Result:=Cardinal(Sockets.StrToHostAddr(IP)); Result:=Cardinal(Sockets.StrToNetAddr(IP));
end;
function NetAddrToStr(const Entry: Cardinal): string; inline;
begin
Result:=Sockets.NetAddrToStr(in_addr(Entry));
end; end;
end. end.

View File

@ -74,11 +74,22 @@ end;
{$else} {$else}
{$ifdef UNIX}
function TZSeconds: integer; inline; function TZSeconds: integer; inline;
begin begin
Result := unixutil.TZSeconds; Result := unixutil.TZSeconds;
end; end;
{$else}
function TZSeconds: integer; inline;
begin
Result := 0; // TODO: implement for non windows, non unix
end;
{$endif}
{$endif} {$endif}
function GMTToLocalTime(ADateTime: TDateTime): TDateTime; function GMTToLocalTime(ADateTime: TDateTime): TDateTime;

View File

@ -11,10 +11,10 @@ uses
implementation implementation
{$ifdef WINDOWS} {$ifdef UNIX}
{$i lspawnfcgiwin.inc}
{$else}
{$i lspawnfcgiunix.inc} {$i lspawnfcgiunix.inc}
{$else}
{$i lspawnfcgiwin.inc}
{$endif} {$endif}
end. end.

View File

@ -1,7 +1,22 @@
{$ifdef WINDOWS} {$ifdef WINDOWS}
Winsock2, Winsock2,
{$else} {$endif}
{$ifdef UNIX}
BaseUnix, NetDB, BaseUnix, NetDB,
{$endif} {$endif}
{$ifdef NETWARE}
WinSock,
{$endif}
{$ifdef OS2}
WinSock,
{$endif}
{$ifdef NETWLIBC}
WinSock,
{$endif}
SysUtils, Sockets; SysUtils, Sockets;