11 using namespace forest;
20 if (listenSock < 0) fatal(
"can't create socket");
22 if (!
Np4d::bind4d(listenSock, myIP, 30124)) fatal(
"can't bind socket");
29 std::cout << connSock <<
"connected" << std::endl;
30 if (connSock < 0) fatal(
"error on accept");
42 pthread_attr_t attr; pthread_attr_init(&attr);
43 pthread_attr_setstacksize(&attr,4*PTHREAD_STACK_MIN);
44 pthread_attr_setdetachstate(&attr,PTHREAD_CREATE_DETACHED);
45 if (pthread_create(&thisThread, &attr, &(
handler), (
void *) sockp) != 0)
46 fatal(
"cannot create thread");
51 int sock = *((
int *) sockp);
delete ((
int *) sockp);
56 if (!buf.readAlphas(s1) || s1 !=
"getPhoto") {
58 close(sock);
return NULL;
61 if (buf.verify(
':')) {
62 if ( !buf.readAlphas(s1)) {
65 close(sock);
return NULL;
68 fileName = string(
"clientPhotos/") + s1 + string(
".jpg");
70 fileName = string(
"clientPhotos/") + s1 +string(
".jpg");
75 ifstream pFile (fileName.c_str(), ios::in | ios::binary | ios::ate);
77 ifstream::pos_type size;
83 memblock =
new char [size];
84 pFile.seekg (0, ios::beg);
85 pFile.read(memblock, size);
88 int bufSize = (int)size;
89 char * ap = &memblock[0];
92 while(bufSize >= CHUNK)
94 Np4d::sendBufBlock(sock, ap, CHUNK);
101 Np4d::sendBufBlock(sock, ap, bufSize);
110 close(sock);
return NULL;
117 close(sock);
return NULL;
120 close(sock);
return NULL;