mirror of
https://github.com/vishapoberon/compiler.git
synced 2026-04-06 06:22:25 +00:00
parent
2615a22901
commit
4f0312705e
3 changed files with 65 additions and 10 deletions
|
|
@ -17,7 +17,7 @@ BEGIN
|
|||
IF n < 0 THEN
|
||||
Out.String("error reading from socket"); Out.Ln;
|
||||
END;
|
||||
Out.String("message is "); Out.String(str); Out.Ln;
|
||||
Out.String("received message is "); Out.String(str); Out.Ln;
|
||||
s := 17;
|
||||
n := Unix.Write(sock, S.ADR(aff), s);
|
||||
IF n < 2 THEN
|
||||
|
|
@ -26,13 +26,27 @@ BEGIN
|
|||
|
||||
END DoSmth;
|
||||
|
||||
PROCEDURE htons(in: Int16; VAR out : Int16);
|
||||
BEGIN
|
||||
out[0] := in[1];
|
||||
out[1] := in[0];
|
||||
END htons;
|
||||
|
||||
|
||||
PROCEDURE ZeroByteArr(VAR a : ARRAY OF S.BYTE);
|
||||
VAR i : LONGINT;
|
||||
BEGIN
|
||||
FOR i := 0 TO LEN(a)-1 DO
|
||||
a[i] := 0
|
||||
END;
|
||||
END ZeroByteArr;
|
||||
|
||||
PROCEDURE serve;
|
||||
VAR sockfd, newsockfd, portno, clilen, pid: sockets.Int32;
|
||||
ServAddr, CliAddr: sockets.SockAddrIn;
|
||||
Null : Int32;
|
||||
Port, maxQueue, res : Int32;
|
||||
afinet, port: Int16;
|
||||
afinet, port, port0: Int16;
|
||||
BEGIN
|
||||
Port := 2055;
|
||||
maxQueue := 5;
|
||||
|
|
@ -47,12 +61,14 @@ BEGIN
|
|||
|
||||
types.IntegerToInt16(sockets.AfInet, afinet);
|
||||
types.IntegerToInt16(Port, port);
|
||||
htons(port, port0); (* only necessary on little endian computers *)
|
||||
ServAddr.SinFamily := afinet;
|
||||
ServAddr.SinPort := port;
|
||||
Out.String("listening on port ");Out.Int(S.VAL(INTEGER, ServAddr.SinPort), 0); Out.Ln;
|
||||
ServAddr.SinPort := port0;
|
||||
ZeroByteArr(ServAddr.SinZero);
|
||||
(*Out.String("listening on port ");Out.Int(S.VAL(INTEGER, ServAddr.SinPort), 0); Out.Ln;*)
|
||||
ServAddr.SinAddr.SAddr := 0(*sockets.InAddrAny*);
|
||||
|
||||
res := sockets.Bind(sockfd, S.VAL(sockets.SockAddr, ServAddr), (SIZE(sockets.SockAddrIn)));
|
||||
res := sockets.Bind(sockfd, S.VAL(sockets.SockAddr, ServAddr), (SIZE(sockets.SockAddr)));
|
||||
IF res < 0 THEN
|
||||
Out.String("error on binding")
|
||||
ELSE
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue