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
|
||||
# (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
|
||||
# basic stuff. we append for a reason.
|
||||
CPPFLAGS=-I../include -DDEBUG -DYY_NO_UNPUT
|
||||
CFLAGS+=-g -Wall -W -ansi ${CPPFLAGS}
|
||||
CFLAGS+=-g -Wall -W -ansi ${CPPFLAGS} -pthread
|
||||
LDFLAGS=-lutil
|
||||
# keep these up to date.
|
||||
MAINBIN=phoned
|
||||
|
|
|
@ -27,7 +27,7 @@
|
|||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* 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 <ctype.h>
|
||||
#include <unistd.h>
|
||||
|
@ -82,7 +82,7 @@ int cid_notify(cid_t* c)
|
|||
char* msg;
|
||||
int s;
|
||||
struct sockaddr_in sin;
|
||||
short on = 0x1;
|
||||
int on = 0x1;
|
||||
addrsll_t *cur;
|
||||
len = strlen(c->number) + strlen(c->name) + 8 + 5 + 4;
|
||||
msg = malloc(len * sizeof(char));
|
||||
|
|
|
@ -42,19 +42,24 @@
|
|||
#include <arpa/inet.h>
|
||||
#include <netinet/in.h>
|
||||
#include <sys/un.h>
|
||||
#include <errno.h>
|
||||
#include <pthread.h>
|
||||
|
||||
#include <phoned.h>
|
||||
|
||||
extern int modemfd;
|
||||
extern FILE* modem;
|
||||
|
||||
void handclient(sk)
|
||||
int sk;
|
||||
void *handclient(k)
|
||||
void* k;
|
||||
{
|
||||
int sk = (int)k;
|
||||
char buffer[1024];
|
||||
int rlen;
|
||||
rlen = recv(sk, buffer, sizeof(buffer), 0);
|
||||
lprintf(debug, "Client said %s.", buffer);
|
||||
close(sk);
|
||||
return 0;
|
||||
}
|
||||
|
||||
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;
|
||||
fd_set fds;
|
||||
int sin_size, ilen;
|
||||
pthread_t thr;
|
||||
char cbuf[1];
|
||||
cbuf[0] = '\0'; cbuf[1] = '\0';
|
||||
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) {
|
||||
ilen = sizeof(it);
|
||||
if((sn = accept(s,
|
||||
(struct sockaddr *)&it, &ilen))
|
||||
if((sn = accept(s, (struct sockaddr *)&it, &ilen))
|
||||
== -1) {
|
||||
perror("s accept");
|
||||
lprintf(error, "accept: %s\n",
|
||||
strerror(errno));
|
||||
exit(-3);
|
||||
}
|
||||
handclient(sn);
|
||||
close(sn);
|
||||
pthread_create(&thr, NULL, handclient, (void*)sn);
|
||||
lprintf(info, "Incoming connection; child pid %d\n"
|
||||
,ilen);
|
||||
|
||||
}
|
||||
if(FD_ISSET(modemfd, &fds) != 0)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue