Initial A34 import

This commit is contained in:
mysticbbs 2013-05-11 23:19:36 -04:00
parent 3d5bef88b1
commit 7df268cb6b
3 changed files with 63 additions and 21 deletions

View File

@ -66,7 +66,7 @@ Type
Function Connect (Address: String; Port: Word) : Boolean; Function Connect (Address: String; Port: Word) : Boolean;
Function ResolveAddress (Host: String) : LongInt; Function ResolveAddress (Host: String) : LongInt;
Procedure WaitInit (NetInterface: String; Port: Word); Procedure WaitInit (NetInterface: String; Port: Word);
Function WaitConnection : TIOSocket; Function WaitConnection (TimeOut: LongInt) : TIOSocket;
Function PeekChar (Num: Byte) : Char; Override; Function PeekChar (Num: Byte) : Char; Override;
Function ReadChar : Char; Override; Function ReadChar : Char; Override;
@ -492,18 +492,39 @@ Begin
If Res < 0 Then Result := -1 Else Result := Length(Str); If Res < 0 Then Result := -1 Else Result := Length(Str);
End; End;
{$IFDEF UNIX}
Function TIOSocket.SetBlocking (Block: Boolean): LongInt; Function TIOSocket.SetBlocking (Block: Boolean): LongInt;
//Var Var
// Data : DWord; Flags : LongInt;
Begin Begin
If FSocketHandle = -1 Then Begin If FSocketHandle = -1 Then Begin
Result := FSocketHandle; Result := FSocketHandle;
Exit; Exit;
End; End;
// Data := Ord(Not Block); Flags := fpFCntl(FSocketHandle, F_GETFL);
// Result := ioctlSocket(FSocketHandle, FIONBIO, Data);
If Block Then
Flags := Flags OR O_NONBLOCK
Else
Flags := Flags AND NOT O_NONBLOCK;
Result := fpFCntl(FSocketHandle, F_SETFL, Flags);
End; End;
{$ELSE}
Function TIOSocket.SetBlocking (Block: Boolean): LongInt;
Var
Data : DWord;
Begin
If FSocketHandle = -1 Then Begin
Result := FSocketHandle;
Exit;
End;
Data := Ord(Not Block);
Result := ioctlSocket(FSocketHandle, FIONBIO, Data);
End;
{$ENDIF}
Function TIOSocket.WaitForData (TimeOut: LongInt) : LongInt; Function TIOSocket.WaitForData (TimeOut: LongInt) : LongInt;
Var Var
@ -594,7 +615,7 @@ Begin
SetBlocking(True); SetBlocking(True);
End; End;
Function TIOSocket.WaitConnection : TIOSocket; Function TIOSocket.WaitConnection (TimeOut: LongInt) : TIOSocket;
Var Var
Sock : LongInt; Sock : LongInt;
Client : TIOSocket; Client : TIOSocket;
@ -605,7 +626,22 @@ Var
Begin Begin
Result := NIL; Result := NIL;
If fpListen(FSocketHandle, 5) = -1 Then Exit; If TimeOut > 0 Then Begin
SetBlocking(False);
If fpListen(FSocketHandle, 5) = -1 Then Begin
SetBlocking(True);
Exit;
End;
If WaitForData(TimeOut) <= 0 Then Begin
SetBlocking(True);
Exit;
End;
End Else
If fpListen(FSocketHandle, 5) = -1 Then Exit;
Temp := SizeOf(SIN); Temp := SizeOf(SIN);
Sock := fpAccept(FSocketHandle, @SIN, @Temp); Sock := fpAccept(FSocketHandle, @SIN, @Temp);

View File

@ -3,20 +3,20 @@ Program Test3;
{$I m_ops.pas} {$I m_ops.pas}
Uses Uses
m_Socket_Class; m_io_Sockets;
Var Var
Server : TSocketClass; Server : TIOSocket;
Client : TSocketClass; Client : TIOSocket;
Str : String; Str : String;
Begin Begin
Server := TSocketClass.Create; Server := TIOSocket.Create;
Server.WaitInit(23); Server.WaitInit('0.0.0.0', 23);
WriteLn('Waiting on port 23 for TEST4 client example...'); WriteLn('Waiting on port 23 for TEST4 client example...');
Client := Server.WaitConnection; Client := Server.WaitConnection(5000);
If Client = NIL Then Begin If Client = NIL Then Begin
WriteLn ('An error has occured; no client detected'); WriteLn ('An error has occured; no client detected');

View File

@ -1,21 +1,27 @@
Program Test4; Program Test4;
Uses Uses
m_Socket_Class; m_io_Sockets;
Var Var
Client : TSocketClass; Client : TIOSocket;
Str : String; Str : String;
Begin Begin
Client := TSocketClass.Create; Client := TIOSocket.Create;
WriteLn ('Attempting to connect to localhost port 23 for TEST3 server test'); WriteLn ('Attempting to connect to localhost port 23 for TEST3 server test');
If Not Client.Connect ('localhost', 23) Then Begin Client.ConnectInit('localhost', 23);
WriteLn ('Connection failed'); Client.SetBlocking(False);
Client.Free;
Halt; Repeat
End; Until Client.Connect;
// If Not Client.Connect ('localhost', 23) Then Begin
// WriteLn ('Connection failed');
// Client.Free;
// Halt;
// End;
Client.ReadLine(Str); Client.ReadLine(Str);