ps2sdk  1.1
A collection of Open Source libraries used for developing applications on Sony's PlayStation 2® (PS2).
echo.c File Reference
#include <tamtypes.h>
#include <kernel.h>
#include <sifrpc.h>
#include <loadfile.h>
#include <stdio.h>
#include <string.h>
#include "ps2ips.h"
+ Include dependency graph for echo.c:

Go to the source code of this file.

Functions

void serverThread ()
 
int main (int argc, char *argv[])
 
int HandleClient (int cs)
 

Variables

char buffer [100]
 

Function Documentation

◆ HandleClient()

int HandleClient ( int  cs)

Definition at line 42 of file echo.c.

43 {
44  int rcvSize,sntSize;
45  // fd_set rd_set;
46 
47  rcvSize = recv( cs, buffer, 100, 0);
48  if ( rcvSize <= 0 )
49  {
50  printf( "PS2ECHO: recv returned %i\n", rcvSize );
51  return -1;
52  }
53  sntSize = send( cs, buffer, rcvSize, 0 );
54 
55  return 0;
56 }
char buffer[100]
Definition: echo.c:39
#define send(a, b, c, d)
Definition: ps2ip.h:66
#define recv(a, b, c, d)
Definition: ps2ip.h:64

References buffer, recv, and send.

Referenced by serverThread().

◆ main()

int main ( int  argc,
char *  argv[] 
)

Definition at line 24 of file echo.c.

25 {
26  SifInitRpc(0);
27 
28  SifLoadModule("host:ps2ips.irx", 0, NULL);
29 
30  if(ps2ip_init() < 0) {
31  printf("ERROR: ps2ip_init falied!\n");
32  SleepThread();
33  }
34 
35  serverThread();
36  return 0;
37 }
void serverThread()
Definition: echo.c:59
int SifLoadModule(const char *path, int arg_len, const char *args)
s32 SleepThread(void)
int ps2ip_init(void)
Definition: ps2ipc.c:60
void SifInitRpc(int mode)
#define NULL
Definition: tamtypes.h:91

References NULL, ps2ip_init(), serverThread(), SifInitRpc(), SifLoadModule(), and SleepThread().

◆ serverThread()

void serverThread ( )

Definition at line 59 of file echo.c.

60 {
61  int sh;
62  int cs;
63  struct sockaddr_in echoServAddr;
64  struct sockaddr_in echoClntAddr;
65  int clntLen;
66  int rc;
67  fd_set active_rd_set;
68  fd_set rd_set;
69 
70  printf( "PS2ECHO: Server Thread Started.\n" );
71 
72 
74  if ( sh < 0 )
75  {
76  printf( "PS2ECHO: Socket failed to create.\n" );
77  SleepThread();
78  }
79 
80  printf( "PS2ECHO: Got socket.. %i\n" , sh );
81 
82 
83  memset( &echoServAddr, 0 , sizeof(echoServAddr ));
84  echoServAddr.sin_family = AF_INET;
85  echoServAddr.sin_addr.s_addr = htonl(INADDR_ANY);
86  echoServAddr.sin_port = htons(12);
87 
88  rc = bind( sh, (struct sockaddr *) &echoServAddr, sizeof( echoServAddr) );
89  if ( rc < 0 )
90  {
91  printf( "PS2ECHO: Socket failed to bind.\n" );
92  SleepThread();
93  }
94 
95  printf( "PS2ECHO: bind returned %i\n",rc );
96 
97 
98  rc = listen( sh, 2 );
99  if ( rc < 0 )
100  {
101  printf( "PS2ECHO: listen failed.\n" );
102  SleepThread();
103  }
104 
105  printf( "PS2ECHO: listen returned %i\n", rc );
106 
107  FD_ZERO(&active_rd_set);
108  FD_SET(sh, &active_rd_set);
109  while(1)
110  {
111  int i;
112  clntLen = sizeof( echoClntAddr );
113  rd_set = active_rd_set;
114  if(select(FD_SETSIZE, &rd_set, NULL, NULL, NULL) < 0)
115  {
116  printf("PS2ECHO: Select failed.\n");
117  SleepThread();
118  }
119 
120  for(i = 0; i < FD_SETSIZE; i++)
121  {
122  if(FD_ISSET(i, &rd_set))
123  {
124  if(i == sh)
125  {
126  cs = accept( sh, (struct sockaddr *)&echoClntAddr, &clntLen );
127  if ( cs < 0 )
128  {
129  printf( "PS2ECHO: accept failed.\n" );
130  SleepThread();
131  }
132  FD_SET(cs, &active_rd_set);
133  printf( "PS2ECHO: accept returned %i.\n", cs );
134  }
135  else
136  {
137  if(HandleClient( i ) < 0)
138  {
139  FD_CLR(i, &active_rd_set);
140  disconnect(i);
141  }
142  }
143  }
144  }
145  }
146 
147  SleepThread();
148 }
int HandleClient(int cs)
Definition: echo.c:42
#define select(a, b, c, d, e)
Definition: ps2ip.h:69
#define listen(a, b)
Definition: ps2ip.h:63
#define accept(a, b, c)
Definition: ps2ip.h:53
#define socket(a, b, c)
Definition: ps2ip.h:68
#define bind(a, b, c)
Definition: ps2ip.h:54
int disconnect(int s)
Definition: ps2ipc.c:151
Definition: tcpip.h:1602
#define FD_ZERO(p)
Definition: tcpip.h:1599
#define SOCK_STREAM
Definition: tcpip.h:1353
#define htons(x)
Definition: tcpip.h:1728
#define INADDR_ANY
Definition: tcpip.h:1294
#define FD_SETSIZE
Definition: tcpip.h:1590
#define IPPROTO_TCP
Definition: tcpip.h:1405
#define AF_INET
Definition: tcpip.h:1393
#define FD_ISSET(n, p)
Definition: tcpip.h:1598
#define FD_SET(n, p)
Definition: tcpip.h:1596
#define htonl(x)
Definition: tcpip.h:1730
#define FD_CLR(n, p)
Definition: tcpip.h:1597

References accept, AF_INET, bind, disconnect(), FD_CLR, FD_ISSET, FD_SET, FD_SETSIZE, FD_ZERO, HandleClient(), htonl, htons, INADDR_ANY, IPPROTO_TCP, listen, NULL, in_addr::s_addr, select, sockaddr_in::sin_addr, sockaddr_in::sin_family, sockaddr_in::sin_port, SleepThread(), SOCK_STREAM, and socket.

Referenced by main().

Variable Documentation

◆ buffer

char buffer[100]

Definition at line 39 of file echo.c.

Referenced by HandleClient().