2 #include "structdefs.h"
3 #include <sys/socket.h>
8 #include "SimpleHash.h"
9 #include "GenericHashtable.h"
11 extern struct RuntimeHash *fdtoobject;
13 int CALL12(___ServerSocket______createSocket____I, int port, struct ___ServerSocket___ * ___this___, int port) {
17 struct sockaddr_in sin;
19 bzero (&sin, sizeof (sin));
20 sin.sin_family = AF_INET;
21 sin.sin_port = htons (port);
22 sin.sin_addr.s_addr = htonl (INADDR_ANY);
23 fd=socket(AF_INET, SOCK_STREAM, 0);
27 printf("createSocket error #1\n");
29 longjmp(error_handler,5);
32 if (setsockopt (fd, SOL_SOCKET, SO_REUSEADDR, (char *)&n, sizeof (n)) < 0) {
36 printf("createSocket error #2\n");
38 longjmp(error_handler, 6);
40 fcntl(fd, F_SETFD, 1);
41 fcntl(fd, F_SETFL, fcntl(fd, F_GETFL)|O_NONBLOCK);
44 if (bind(fd, (struct sockaddr *) &sin, sizeof(sin))<0) {
48 printf("createSocket error #3\n");
50 longjmp(error_handler, 7);
54 if (listen(fd, 5)<0) {
58 printf("createSocket error #4\n");
60 longjmp(error_handler, 8);
63 /* Store the fd/socket object mapping */
64 RuntimeHashadd(fdtoobject, fd, (int) VAR(___this___));
69 int CALL02(___ServerSocket______nativeaccept____L___Socket___,struct ___ServerSocket___ * ___this___, struct ___Socket___ * ___s___) {
70 struct sockaddr_in sin;
71 unsigned int sinlen=sizeof(sin);
72 int fd=VAR(___this___)->___fd___;
74 newfd=accept(fd, (struct sockaddr *)&sin, &sinlen);
80 printf("acceptSocket error #1\n");
82 longjmp(error_handler, 9);
84 fcntl(newfd, F_SETFL, fcntl(fd, F_GETFL)|O_NONBLOCK);
86 RuntimeHashadd(fdtoobject, newfd, (int) VAR(___s___));
88 flagorand(VAR(___this___),0,0xFFFFFFFE);
93 void CALL02(___Socket______nativeWrite_____AR_B, struct ___Socket___ * ___this___, struct ArrayObject * ___b___) {
94 int fd=VAR(___this___)->___fd___;
95 int length=VAR(___b___)->___length___;
96 char * charstr=((char *)& VAR(___b___)->___length___)+sizeof(int);
98 int bytewritten=write(fd, charstr, length);
99 if (bytewritten==-1&&errno==EAGAIN)
102 if (bytewritten!=length) {
103 perror("ERROR IN NATIVEWRITE");
107 // flagorand(VAR(___this___),0,0xFFFFFFFE);
110 int CALL02(___Socket______nativeRead_____AR_B, struct ___Socket___ * ___this___, struct ArrayObject * ___b___) {
111 int fd=VAR(___this___)->___fd___;
112 int length=VAR(___b___)->___length___;
113 char * charstr=((char *)& VAR(___b___)->___length___)+sizeof(int);
114 int byteread=read(fd, charstr, length);
117 printf("ERROR IN NATIVEREAD\n");
119 flagorand(VAR(___this___),0,0xFFFFFFFE);
123 void CALL01(___Socket______nativeClose____, struct ___Socket___ * ___this___) {
124 int fd=VAR(___this___)->___fd___;
126 RuntimeHashget(fdtoobject, fd, &data);
127 RuntimeHashremove(fdtoobject, fd, data);
130 flagorand(VAR(___this___),0,0xFFFFFFFE);