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;
60 if (buf.verify(
':')) {
62 if (buf.readAlphas(s2) && s2 !=
""){
64 fileName = string(
"clientPhotos/") + s2 + string(
".jpg");
65 std::cout << fileName << std::endl;
68 ifstream pFile (fileName.c_str(), ios::in | ios::binary | ios::ate);
70 ifstream::pos_type size;
75 std::cout <<
"file opened" << std::endl;
77 memblock =
new char [size];
78 pFile.seekg (0, ios::beg);
79 pFile.read(memblock, size);
82 int bufSize = (int)size;
85 ss <<
"success:" << bufSize;
86 string echo = ss.str();
87 while (echo.size() < 14)
93 char * ap = &memblock[0];
96 while(bufSize >= CHUNK)
98 Np4d::sendBufBlock(sock, ap, CHUNK);
105 Np4d::sendBufBlock(sock, ap, bufSize);
112 std::cout <<
"didn't open" << std::endl;
114 close(sock);
return NULL;
118 std::cout <<
"hmmmm" << std::endl;
121 close(sock);
return NULL;
127 close(sock);
return NULL;
130 close(sock);
return NULL;