Threads....
This commit is contained in:
parent
6aaed38c04
commit
a762870fb3
3 changed files with 19 additions and 11 deletions
|
@ -1,10 +1,10 @@
|
||||||
# cnd Makefile
|
# cnd Makefile
|
||||||
# (C)2005, Dan Ponte
|
# (C)2005, Dan Ponte
|
||||||
# $Amigan: phoned/phoned/Makefile,v 1.7 2005/06/02 02:45:35 dcp1990 Exp $
|
# $Amigan: phoned/phoned/Makefile,v 1.8 2005/06/02 20:49:26 dcp1990 Exp $
|
||||||
include ../global.mk
|
include ../global.mk
|
||||||
# basic stuff. we append for a reason.
|
# basic stuff. we append for a reason.
|
||||||
CPPFLAGS=-I../include -DDEBUG -DYY_NO_UNPUT
|
CPPFLAGS=-I../include -DDEBUG -DYY_NO_UNPUT
|
||||||
CFLAGS+=-g -Wall -W -ansi ${CPPFLAGS}
|
CFLAGS+=-g -Wall -W -ansi ${CPPFLAGS} -pthread
|
||||||
LDFLAGS=-lutil
|
LDFLAGS=-lutil
|
||||||
# keep these up to date.
|
# keep these up to date.
|
||||||
MAINBIN=phoned
|
MAINBIN=phoned
|
||||||
|
|
|
@ -27,7 +27,7 @@
|
||||||
* 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/notify.c,v 1.1 2005/06/02 02:40:53 dcp1990 Exp $ */
|
/* $Amigan: phoned/phoned/notify.c,v 1.2 2005/06/02 20:49:26 dcp1990 Exp $ */
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
@ -82,7 +82,7 @@ int cid_notify(cid_t* c)
|
||||||
char* msg;
|
char* msg;
|
||||||
int s;
|
int s;
|
||||||
struct sockaddr_in sin;
|
struct sockaddr_in sin;
|
||||||
short on = 0x1;
|
int on = 0x1;
|
||||||
addrsll_t *cur;
|
addrsll_t *cur;
|
||||||
len = strlen(c->number) + strlen(c->name) + 8 + 5 + 4;
|
len = strlen(c->number) + strlen(c->name) + 8 + 5 + 4;
|
||||||
msg = malloc(len * sizeof(char));
|
msg = malloc(len * sizeof(char));
|
||||||
|
|
|
@ -42,19 +42,24 @@
|
||||||
#include <arpa/inet.h>
|
#include <arpa/inet.h>
|
||||||
#include <netinet/in.h>
|
#include <netinet/in.h>
|
||||||
#include <sys/un.h>
|
#include <sys/un.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <pthread.h>
|
||||||
|
|
||||||
#include <phoned.h>
|
#include <phoned.h>
|
||||||
|
|
||||||
extern int modemfd;
|
extern int modemfd;
|
||||||
extern FILE* modem;
|
extern FILE* modem;
|
||||||
|
|
||||||
void handclient(sk)
|
void *handclient(k)
|
||||||
int sk;
|
void* k;
|
||||||
{
|
{
|
||||||
|
int sk = (int)k;
|
||||||
char buffer[1024];
|
char buffer[1024];
|
||||||
int rlen;
|
int rlen;
|
||||||
rlen = recv(sk, buffer, sizeof(buffer), 0);
|
rlen = recv(sk, buffer, sizeof(buffer), 0);
|
||||||
lprintf(debug, "Client said %s.", buffer);
|
lprintf(debug, "Client said %s.", buffer);
|
||||||
|
close(sk);
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void network(void) /* name is misleading because we also do modem IO here */
|
void network(void) /* name is misleading because we also do modem IO here */
|
||||||
|
@ -62,6 +67,7 @@ void network(void) /* name is misleading because we also do modem IO here */
|
||||||
int s, /* us,*/ sn;
|
int s, /* us,*/ sn;
|
||||||
fd_set fds;
|
fd_set fds;
|
||||||
int sin_size, ilen;
|
int sin_size, ilen;
|
||||||
|
pthread_t thr;
|
||||||
char cbuf[1];
|
char cbuf[1];
|
||||||
cbuf[0] = '\0'; cbuf[1] = '\0';
|
cbuf[0] = '\0'; cbuf[1] = '\0';
|
||||||
struct sockaddr_un it;
|
struct sockaddr_un it;
|
||||||
|
@ -98,14 +104,16 @@ void network(void) /* name is misleading because we also do modem IO here */
|
||||||
{
|
{
|
||||||
if(FD_ISSET(s, &fds) != 0) {
|
if(FD_ISSET(s, &fds) != 0) {
|
||||||
ilen = sizeof(it);
|
ilen = sizeof(it);
|
||||||
if((sn = accept(s,
|
if((sn = accept(s, (struct sockaddr *)&it, &ilen))
|
||||||
(struct sockaddr *)&it, &ilen))
|
|
||||||
== -1) {
|
== -1) {
|
||||||
perror("s accept");
|
lprintf(error, "accept: %s\n",
|
||||||
|
strerror(errno));
|
||||||
exit(-3);
|
exit(-3);
|
||||||
}
|
}
|
||||||
handclient(sn);
|
pthread_create(&thr, NULL, handclient, (void*)sn);
|
||||||
close(sn);
|
lprintf(info, "Incoming connection; child pid %d\n"
|
||||||
|
,ilen);
|
||||||
|
|
||||||
}
|
}
|
||||||
if(FD_ISSET(modemfd, &fds) != 0)
|
if(FD_ISSET(modemfd, &fds) != 0)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue