#define TESTL 4
CONTYP *contact;
+int client_fd;
pid_t child;
int phase;
_Bool proceed;
(void) prc_settitle("Waiting contact on %s:%s",binding->ip,binding->port);
break;
case 1 : //do we have a contact
- if ((contact=tcp_getcontact(binding))==(CONTYP *)0) {
- phase=999; //no going further
- }
+ client_fd=accept(binding->handle,NULL,NULL);
+ printf("New client connected: %d\n",client_fd);
break;
case 2 : //forking process
if ((child=fork())!=(pid_t)0) {
- (void) close(contact->channel);
- (void) free(contact);
- (void) sleep(8);
+ (void) close(client_fd);
(void) fprintf(stdout,"JMPDBG retart\n");
phase=0;
}
case 3 : //do contact
(void) close(binding->handle);
for (int i=0;i<TESTL;i++) {
- int sent;
- char tmpbuf[100];
-
- if ((reload==true)||(hangup==true))
- break;
- if (prc_checkprocess(getppid())==false)
- break;
- sent=tcp_fprintf(contact,"Remote pid=%d iter=%d/%d\n",getpid(),i,TESTL);
- if (sent<0) {
- (void) rou_alert(0,"JMPDBG tcp_fprintf error <%s>",strerror(errno));
- break;
- }
- (void) read(contact->channel,tmpbuf,sizeof(tmpbuf));
+ (void) dprintf(client_fd,"Remote pid=%d iter=%d/%d\n",getpid(),i,TESTL);
(void) sleep(1);
}
break;
case 4 : //close contact
- contact=tcp_dropcontact(contact);
+ if (shutdown(client_fd,SHUT_RDWR)<0) {
+ (void) printf("Unable to shutdown properly (error=<%s>)\n",strerror(errno));
+ }
+ if (close(client_fd)<0) {
+ (void) printf("Unable to close properly (error=<%s>(\n",strerror(errno));
+ }
(void) exit(0);
break;
default : //SAFE guard
/* to handle TCP socket. */
/* */
/********************************************************/
+#include <arpa/inet.h>
#include <sys/types.h>
#include <errno.h>
#include <fcntl.h>
int handle;
struct linger slg;
+struct sockaddr_in server_addr;
int reuse;
int phase;
_Bool proceed;
while (proceed==true) {
switch (phase) {
case 0 : //lets get a socket
- if ((handle=socket(ai->ai_family,ai->ai_socktype,ai->ai_protocol))<0) {
+ if ((handle=socket(AF_INET, SOCK_STREAM,0))<0) {
+ //if ((handle=socket(ai->ai_family,ai->ai_socktype,ai->ai_protocol))<0) {
(void) rou_alert(0,"%s Unable to open socket for <%s> (error='%s')",
OPEP,ai->ai_canonname,strerror(errno));
phase=999; //trouble trouble
}
break;
case 4 : //getting socket option
- if (bind(handle,ai->ai_addr,ai->ai_addrlen)<0) {
+ server_addr.sin_family = AF_INET;
+ inet_pton(AF_INET,"127.0.0.1", &(server_addr.sin_addr));
+ server_addr.sin_port = htons(2525);
+ if (bind(handle,(struct sockaddr*) &server_addr, sizeof(server_addr))<0) {
+ //if (bind(handle,ai->ai_addr,ai->ai_addrlen)<0) {
(void) rou_alert(0,"%s Unable to bind on IP/port <%s/%s> (error='%s')",
OPEP,ai->ai_canonname,binding->port,strerror(errno));
phase=999; //trouble cleanup phase
}
break;
case 1 : //
+ break;
if ((setegid(getgid())<0)||(seteuid(getuid())<0)) {
(void) rou_core_dump("%s, Unable to get root privilege! "
"(program config? error=<%s>)",