git.ucc.asn.au
/
tpg
/
acess2.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Usermode/libc - More errno values and signal symbolic names
[tpg/acess2.git]
/
Usermode
/
Applications
/
telnetd_src
/
main.c
diff --git
a/Usermode/Applications/telnetd_src/main.c
b/Usermode/Applications/telnetd_src/main.c
index
198ddaa
..
16dac83
100644
(file)
--- a/
Usermode/Applications/telnetd_src/main.c
+++ b/
Usermode/Applications/telnetd_src/main.c
@@
-1,9
+1,15
@@
/*
/*
+ * Acess2 Telnet Server (TCP server test case)
+ * - By John Hodge (thePowersGang)
+ *
+ * main.c
+ * - All
*/
#include <stddef.h>
#include <net.h>
*/
#include <stddef.h>
#include <net.h>
-#include <unistd.h>
#include <stdio.h>
#include <stdio.h>
+#include <stdlib.h>
+#include <acess/sys.h>
// === TYPES ===
typedef struct sClient
// === TYPES ===
typedef struct sClient
@@
-36,7
+42,13
@@
int main(int argc, char *argv[])
gaClients = calloc(giConfig_MaxClients, sizeof(tClient));
// Open server
gaClients = calloc(giConfig_MaxClients, sizeof(tClient));
// Open server
- giServerFD = Net_OpenSocket(0, NULL, "tcps");
+ {
+ uint8_t data[16];
+ int addrtype = Net_ParseAddress("10.0.2.10", data);
+ int port = 23;
+ giServerFD = Net_OpenSocket(addrtype, data, "tcps");
+ _SysIOCtl(giServerFD, 4, &port); // Set port and start listening
+ }
// Event loop
EventLoop();
// Event loop
EventLoop();
@@
-44,30
+56,34
@@
int main(int argc, char *argv[])
return 0;
}
return 0;
}
+static void FD_SET_MAX(fd_set *set, int fd, int *maxfd)
+{
+ FD_SET(fd, set);
+ if(*maxfd < fd) *maxfd = fd;
+}
+
void EventLoop(void)
{
fd_set fds;
int maxfd;
void EventLoop(void)
{
fd_set fds;
int maxfd;
- void FD_SET_MAX(fd_set *set, int fd, int *maxfd)
- {
- FD_SET(fd, set);
- if(*maxfd < fd) *maxfd = fd;
- }
-
for( ;; )
{
for( ;; )
{
+ FD_ZERO(&fds);
maxfd = 0;
// Fill select
FD_SET_MAX(&fds, giServerFD, &maxfd);
for( int i = 0; i < giConfig_MaxClients; i ++ )
{
maxfd = 0;
// Fill select
FD_SET_MAX(&fds, giServerFD, &maxfd);
for( int i = 0; i < giConfig_MaxClients; i ++ )
{
+ if( gaClients[i].Socket == 0 ) continue ;
+ _SysDebug("Socket = %i, stdout = %i",
+ gaClients[i].Socket, gaClients[i].stdout);
FD_SET_MAX(&fds, gaClients[i].Socket, &maxfd);
FD_SET_MAX(&fds, gaClients[i].stdout, &maxfd);
}
// Select!
FD_SET_MAX(&fds, gaClients[i].Socket, &maxfd);
FD_SET_MAX(&fds, gaClients[i].stdout, &maxfd);
}
// Select!
-
select( maxfd+1, &fds, NULL, NULL, NULL
);
+
_SysSelect( maxfd+1, &fds, NULL, NULL, NULL, 0
);
// Check events
if( FD_ISSET(giServerFD, &fds) )
// Check events
if( FD_ISSET(giServerFD, &fds) )
@@
-98,7
+114,7
@@
void Server_NewClient(int FD)
if( giNumClients == giConfig_MaxClients )
{
// Open, reject
if( giNumClients == giConfig_MaxClients )
{
// Open, reject
-
close( _SysOpenChild(FD, "", O_RDWR
) );
+
_SysClose( _SysOpenChild(FD, "", OPENFLAG_READ
) );
return ;
}
return ;
}
@@
-111,17
+127,18
@@
void Server_NewClient(int FD)
}
}
// Accept the connection
}
}
// Accept the connection
- clt->Socket = _SysOpenChild(FD, "", O
_RDWR
);
- giNumClients ++;
+ clt->Socket = _SysOpenChild(FD, "", O
PENFLAG_READ|OPENFLAG_WRITE
);
+ giNumClients ++;
// Create stdin/stdout
// Create stdin/stdout
- clt->stdin =
open("/Devices/fifo", O_RDWR
);
- clt->stdout =
open("/Devices/fifo", O_RDWR
);
+ clt->stdin =
_SysOpen("/Devices/fifo/anon", OPENFLAG_READ|OPENFLAG_WRITE
);
+ clt->stdout =
_SysOpen("/Devices/fifo/anon", OPENFLAG_READ|OPENFLAG_WRITE
);
// TODO: Arguments and envp
{
int fds[3] = {clt->stdin, clt->stdout, clt->stdout};
// TODO: Arguments and envp
{
int fds[3] = {clt->stdin, clt->stdout, clt->stdout};
- _SysSpawn("/Acess/SBin/login", NULL, NULL, 3, fds);
+ const char *argv[] = {NULL};
+ _SysSpawn("/Acess/SBin/login", argv, argv, 3, fds, NULL);
}
}
}
}
@@
-130,8
+147,9
@@
void HandleServerBoundData(tClient *Client)
char buf[BUFSIZ];
int len;
char buf[BUFSIZ];
int len;
- len = read(Client->Socket, buf, BUFSIZ);
- write(Client->stdin, buf, len);
+ len = _SysRead(Client->Socket, buf, BUFSIZ);
+ if( len <= 0 ) return ;
+ _SysWrite(Client->stdin, buf, len);
}
void HandleClientBoundData(tClient *Client)
}
void HandleClientBoundData(tClient *Client)
@@
-139,7
+157,8
@@
void HandleClientBoundData(tClient *Client)
char buf[BUFSIZ];
int len;
char buf[BUFSIZ];
int len;
- len = read(Client->stdout, buf, BUFSIZ);
- write(Client->Socket, buf, len);
+ len = _SysRead(Client->stdout, buf, BUFSIZ);
+ if( len <= 0 ) return ;
+ _SysWrite(Client->Socket, buf, len);
}
}
UCC
git Repository :: git.ucc.asn.au