Use send() and recv()...they work.

This commit is contained in:
dcp1990 2005-06-13 22:02:27 +00:00
parent 1f5e47bc90
commit 27f8130e96
3 changed files with 17 additions and 7 deletions

View file

@ -28,11 +28,13 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE. * SUCH DAMAGE.
*/ */
/* $Amigan: phoned/phoned/remote.c,v 1.2 2005/06/13 21:04:14 dcp1990 Exp $ */ /* $Amigan: phoned/phoned/remote.c,v 1.3 2005/06/13 22:02:27 dcp1990 Exp $ */
/* system includes */ /* system includes */
#include <string.h> #include <string.h>
#include <stdio.h> #include <stdio.h>
#include <pthread.h> #include <pthread.h>
#include <sys/types.h>
#include <sys/socket.h>
/* us */ /* us */
#include <phoned.h> #include <phoned.h>
#define MAXBUFSIZE 512 #define MAXBUFSIZE 512
@ -75,6 +77,7 @@ char *parse_command(cmd, cont, s)
c.minute = 20; c.minute = 20;
cid_notify(&c); cid_notify(&c);
cid_log(&c); cid_log(&c);
*cont = 0;
RNF("500 OK: Notify tested.\n"); RNF("500 OK: Notify tested.\n");
} else if(CHK("tparse")) { } else if(CHK("tparse")) {
cid_t* rc; cid_t* rc;
@ -82,9 +85,11 @@ char *parse_command(cmd, cont, s)
lprintf(info, "nam=%s;month=%d\n", rc->name, rc->month); lprintf(info, "nam=%s;month=%d\n", rc->name, rc->month);
cid_notify(rc); cid_notify(rc);
cid_log(rc); cid_log(rc);
*cont = 0;
RNF("500 OK: Parser tested.\n"); RNF("500 OK: Parser tested.\n");
} else if(CHK("gmm")) { } else if(CHK("gmm")) {
give_me_modem(argvect[1] != NULL ? argvect[1] : "AT\r\n"); give_me_modem(argvect[1] != NULL ? argvect[1] : "AT\r\n");
*cont = 0;
RNF("500 OK: Give Me Modem tested.\n"); RNF("500 OK: Give Me Modem tested.\n");
} }
break; break;
@ -95,8 +100,9 @@ char *parse_command(cmd, cont, s)
} }
return NULL; return NULL;
} }
void begin_dialogue(fp) void begin_dialogue(fp, fd)
FILE* fp; FILE* fp;
int fd;
{ {
char buffer[MAXBUFSIZE]; /* molto importante */ char buffer[MAXBUFSIZE]; /* molto importante */
char *rcode, *c; char *rcode, *c;
@ -104,13 +110,14 @@ void begin_dialogue(fp)
state_info_t si; state_info_t si;
memset(&si, 0, sizeof(state_info_t)); memset(&si, 0, sizeof(state_info_t));
si.fpo = fp; /* this is JUST for data, not real commands */ si.fpo = fp; /* this is JUST for data, not real commands */
si.fd = fd;
while(keep_going == 0x1 && !feof(fp)) { while(keep_going == 0x1 && !feof(fp)) {
if(fgets(buffer, MAXBUFSIZE, fp) == 0x0) break; if(recv(fd, buffer, MAXBUFSIZE - 1, 0x0) == -1) break;
if((c = strrchr(buffer, '\n')) != NULL) if((c = strrchr(buffer, '\n')) != NULL)
*c = '\0'; *c = '\0';
rcode = parse_command(buffer, &keep_going, &si); rcode = parse_command(buffer, &keep_going, &si);
if(rcode != NULL) { if(rcode != NULL) {
fputs(rcode, fp); send(fd, rcode, strlen(rcode) + 1, 0);
if(si.freeit) free(rcode); if(si.freeit) free(rcode);
} }
} }

View file

@ -42,7 +42,6 @@ void handsig(sig)
case SIGINT: case SIGINT:
case SIGQUIT: case SIGQUIT:
case SIGTERM: case SIGTERM:
case SIGPIPE:
lprintf(fatal, "Received signal %d, cleaning up...\n", sig); lprintf(fatal, "Received signal %d, cleaning up...\n", sig);
shutd(); shutd();
exit(0); exit(0);
@ -50,6 +49,11 @@ void handsig(sig)
case SIGHUP: case SIGHUP:
lprintf(info, "Received HUP, rereading configuration files...\n"); lprintf(info, "Received HUP, rereading configuration files...\n");
break; break;
#ifdef DEBUG
case SIGPIPE:
abort();
break;
#endif
default: default:
lprintf(warn, "Received signal %d!\n", sig); lprintf(warn, "Received signal %d!\n", sig);
} }

View file

@ -55,9 +55,8 @@ void *handclient(k)
{ {
int sk = (int)k; int sk = (int)k;
FILE* tf; FILE* tf;
lprintf(info, "Incoming client.");
tf = fdopen(sk, "r+"); tf = fdopen(sk, "r+");
begin_dialogue(tf); begin_dialogue(tf, sk);
fclose(tf); fclose(tf);
pthread_exit(NULL); pthread_exit(NULL);
return 0; return 0;