#include < pthread.h >
#include < stdio.h >
#include "socketfun.h"
typedef struct {
int fd;
FILE *fout;
int *nchars;
pthread_mutex_t *lock;
} TStruct;
int read1000(int fd, char *chars)
{
int so_far, i;
so_far = 0;
while(so_far < 1000) {
i = read(fd, chars+so_far,
1000-so_far);
if (i == 0) return 0;
so_far += i;
}
return 1;
}
void *service_thread(void *arg)
{
TStruct *t;
t = (TStruct *) arg;
/* Add code here: */
}
|
main()
{
int sock;
int fd;
FILE *fout;
int nchars;
pthread_t tid;
TStruct *t;
pthread_mutex_t lock;
sock = serve_socket("cetus3a", 15000);
if (sock < 0)
{ perror("serve_socket"); exit(1); }
fout = fopen("outfile", "w");
if (fout == NULL)
{ perror("fopen(outfile)"); exit(1); }
nchars = 0;
pthread_mutex_init(&lock, NULL);
while (1) {
fd = accept_connection(sock);
/* Add code here: */
}
}
|