ReactOS 0.4.15-dev-5666-gc548b97
srltest.c File Reference
#include <unistd.h>
#include <sys/types.h>
#include <sys/time.h>
#include <sys/socket.h>
#include <sys/wait.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <errno.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>
#include <ctype.h>
#include "sio.h"
Include dependency graph for srltest.c:

Go to the source code of this file.

Functions

static void ServeOneClient (int sockfd, struct sockaddr_in *cliAddr)
 
static void Server (int port)
 
void main (int argc, char **argv)
 

Function Documentation

◆ main()

void main ( int argc  ,
char **  argv 
)

Definition at line 107 of file srltest.c.

108{
109 int port;
110
111 if (argc < 2) {
112 fprintf(stderr, "Usage: %s <port>\n", argv[0]);
113 exit(2);
114 }
115 port = atoi(argv[1]);
116 Server(port);
117 exit(0);
118} /* main */
static int argc
Definition: ServiceArgs.c:12
USHORT port
Definition: uri.c:228
#define stderr
Definition: stdio.h:100
_Check_return_opt_ _CRTIMP int __cdecl fprintf(_Inout_ FILE *_File, _In_z_ _Printf_format_string_ const char *_Format,...)
_Check_return_ int __cdecl atoi(_In_z_ const char *_Str)
#define argv
Definition: mplay32.c:18
#define exit(n)
Definition: config.h:202
static void Server(int port)
Definition: srltest.c:69

◆ ServeOneClient()

static void ServeOneClient ( int  sockfd,
struct sockaddr_in cliAddr 
)
static

Definition at line 23 of file srltest.c.

24{
25 char buf[80], cliAddrStr[64];
26 char bbuf[320];
27 int nread, nwrote, i;
28 SReadlineInfo srl;
29
30 printf("subserver[%d]: started, connected to %s.\n", (int) getpid(),
31 AddrToAddrStr(cliAddrStr, sizeof(cliAddrStr), cliAddr, 1, "<%h:%p>")
32 );
33
34 if (InitSReadlineInfo(&srl, sockfd, bbuf, sizeof(bbuf), 5) < 0) {
35 fprintf(stderr, "subserver[%d]: InitSReadlineInfo error: %s\n",
36 (int) getpid(), strerror(errno));
37 exit(1);
38 }
39 for (;;) {
40 nread = SReadline(&srl, buf, sizeof(buf));
41 if (nread == 0) {
42 break;
43 } else if (nread == kTimeoutErr) {
44 printf("subserver[%d]: idle\n", (int) getpid());
45 continue;
46 } else if (nread < 0) {
47 fprintf(stderr, "subserver[%d]: read error: %s\n",
48 (int) getpid(), strerror(errno));
49 break;
50 }
51 for (i=0; i<nread; i++)
52 if (islower(buf[i]))
53 buf[i] = toupper(buf[i]);
54 nwrote = SWrite(sockfd, buf, nread, 15);
55 if (nwrote < 0) {
56 fprintf(stderr, "subserver[%d]: write error: %s\n",
57 (int) getpid(), strerror(errno));
58 break;
59 }
60 }
61 (void) SClose(sockfd, 10);
62 printf("subserver[%d]: done.\n", (int) getpid());
63 exit(0);
64} /* ServeOneClient */
int SClose(int sfd, int tlen)
Definition: SClose.c:9
#define islower(c)
Definition: acclib.h:72
int toupper(int c)
Definition: utclib.c:881
#define printf
Definition: freeldr.h:94
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
int SWrite(int, const char *const, size_t, int, int)
Definition: SWrite.c:90
char * AddrToAddrStr(char *const dst, size_t dsize, struct sockaddr_in *const saddrp, int dns, const char *fmt)
Definition: StrAddr.c:136
int SReadline(SReadlineInfo *, char *const, size_t)
Definition: SReadline.c:76
int InitSReadlineInfo(SReadlineInfo *, int, char *, size_t, int, int)
Definition: SReadline.c:24
#define kTimeoutErr
Definition: sio.h:58
const char * strerror(int err)
Definition: compat_str.c:23
#define errno
Definition: errno.h:18
#define getpid
Definition: wintirpc.h:52

Referenced by Server().

◆ Server()

static void Server ( int  port)
static

Definition at line 69 of file srltest.c.

70{
71 int sockfd, newsockfd;
72 struct sockaddr_in cliAddr;
73 int pid;
74
75 sockfd = SNewStreamServer(port, 3, kReUseAddrYes, 3);
76 if (sockfd < 0) {
77 perror("Server setup failed");
78 exit(1);
79 }
80
81 printf("server[%d]: started.\n", (int) getpid());
82 for(;;) {
83 while (waitpid(-1, NULL, WNOHANG) > 0) ;
84 newsockfd = SAccept(sockfd, &cliAddr, 5);
85 if (newsockfd < 0) {
86 if (newsockfd == kTimeoutErr)
87 printf("server[%d]: idle\n", (int) getpid());
88 else
89 fprintf(stderr, "server[%d]: accept error: %s\n",
90 (int) getpid(), strerror(errno));
91 } else if ((pid = fork()) < 0) {
92 fprintf(stderr, "server[%d]: fork error: %s\n",
93 (int) getpid(), strerror(errno));
94 exit(1);
95 } else if (pid == 0) {
96 ServeOneClient(newsockfd, &cliAddr);
97 exit(0);
98 } else {
99 /* Parent doesn't need it now. */
100 (void) close(newsockfd);
101 }
102 }
103} /* Server */
#define close
Definition: acwin.h:98
#define NULL
Definition: types.h:112
#define WNOHANG
Definition: linux.h:1333
_CRTIMP void __cdecl perror(_In_opt_z_ const char *_ErrMsg)
#define kReUseAddrYes
Definition: sio.h:45
int SNewStreamServer(const int, const int, const int, int)
Definition: SNew.c:34
#define SAccept
Definition: sio.h:81
static void ServeOneClient(int sockfd, struct sockaddr_in *cliAddr)
Definition: srltest.c:23
_In_ ULONG_PTR _In_ ULONG _Out_ ULONG_PTR * pid
Definition: winddi.h:3837

Referenced by _tmain(), CreateNameServerListCallback(), CreateNameServerListEnumNamesFunc(), main(), NetAddAlternateComputerName(), NetEnumerateComputerNames(), NetRemoveAlternateComputerName(), NetSetPrimaryComputerName(), ParseCommandLine(), and ScControl().