Skip to content

Commit 777c183

Browse files
committed
1 parent 88f2f6e commit 777c183

File tree

8 files changed

+41
-21
lines changed

8 files changed

+41
-21
lines changed

simple_test/nbproject/build-impl.xml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -291,15 +291,18 @@ is divided into following sections:
291291
<attribute default="${build.classes.dir}" name="destdir"/>
292292
<sequential>
293293
<fail unless="javac.includes">Must set javac.includes</fail>
294-
<pathconvert pathsep="," property="javac.includes.binary">
294+
<pathconvert pathsep="${line.separator}" property="javac.includes.binary">
295295
<path>
296296
<filelist dir="@{destdir}" files="${javac.includes}"/>
297297
</path>
298298
<globmapper from="*.java" to="*.class"/>
299299
</pathconvert>
300+
<tempfile deleteonexit="true" property="javac.includesfile.binary"/>
301+
<echo file="${javac.includesfile.binary}" message="${javac.includes.binary}"/>
300302
<delete>
301-
<files includes="${javac.includes.binary}"/>
303+
<files includesfile="${javac.includesfile.binary}"/>
302304
</delete>
305+
<delete file="${javac.includesfile.binary}"/>
303306
</sequential>
304307
</macrodef>
305308
</target>

simple_test/nbproject/genfiles.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@ build.xml.stylesheet.CRC32=28e38971@1.38.1.45
44
# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml.
55
# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you.
66
nbproject/build-impl.xml.data.CRC32=8068a516
7-
nbproject/build-impl.xml.script.CRC32=05998054
8-
nbproject/build-impl.xml.stylesheet.CRC32=f33e10ff@1.38.2.45
7+
nbproject/build-impl.xml.script.CRC32=34f79022
8+
nbproject/build-impl.xml.stylesheet.CRC32=229523de@1.38.3.45
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
compile.on.save=true
2-
user.properties.file=C:\\Users\\Lukas Elmer\\.netbeans\\6.9\\build.properties
2+
user.properties.file=D:\\Users\\Lukas Elmer\\.netbeans\\6.9\\build.properties

u11_testat/ServerSocket.cpp

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,22 @@ ServerSocket::~ServerSocket() {
1111
doClose();
1212
}
1313

14+
bool ServerSocket::setSocketOptions() {
15+
char x = 1;
16+
if (setsockopt(sockfd, SOL_SOCKET, SO_KEEPALIVE, (const char*) &x, sizeof (x)) == -1) {
17+
return false;
18+
}
19+
//set reuse socket opt
20+
if (setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, (const char*) &x, sizeof (x)) == -1) {
21+
return false;
22+
}
23+
return true;
24+
}
25+
1426
bool ServerSocket::prepareServerSocket() {
1527
sockfd = socket(AF_INET, SOCK_STREAM, 0);
16-
//set reuse socket opt
1728
char x = 1;
18-
if (setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, (const char*) &x, sizeof (x))) {
29+
if (!setSocketOptions()) {
1930
return false;
2031
}
2132

u11_testat/ServerSocket.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ class ServerSocket {
2121
bool prepareServerSocket();
2222
int doAccept();
2323
void doClose();
24+
bool setSocketOptions();
2425
private:
2526
int sockfd;
2627
unsigned short port;

u11_testat/SocketIO.cpp

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,15 @@
22

33
using namespace std;
44

5-
SocketIO::SocketIO(int fd) : sock(fd), /*writePtr(buf), readPtr(buf), endPtr(buf + sizeof (buf)),*/ eof_reached(true) {
5+
SocketIO::SocketIO(int fd) : sock(fd), lines(""), /*writePtr(buf), readPtr(buf), endPtr(buf + sizeof (buf)),*/ eof_reached(true) {
66
}
77

88
SocketIO::~SocketIO() {
99
this->doClose();
1010
}
1111

1212
string SocketIO::readlines() {
13-
fillbuf();
14-
if (eof_reached) {
15-
return "";
16-
}
17-
eof_reached = true;
13+
while (fillbuf());
1814
return lines;
1915
}
2016

@@ -30,6 +26,10 @@ void SocketIO::doClose() {
3026
sock = -1;
3127
}
3228

29+
void SocketIO::closeReadSocket() {
30+
shutdown(sock, SHUT_RD);
31+
}
32+
3333
string SocketIO::getPeerInfo() {
3434
struct sockaddr_in peerInfo;
3535
socklen_t len = sizeof (peerInfo);
@@ -43,12 +43,13 @@ string SocketIO::getPeerInfo() {
4343
}
4444

4545
bool SocketIO::fillbuf() { // corresponds to streambuf::underflow()
46-
int i = recv(sock, buf, BUF_SIZE, 0);
47-
if (i < 0) {
48-
lines = "";
46+
int i = recv(sock, buf, BUF_SIZE, MSG_DONTWAIT);
47+
if (i <= 0) {
48+
eof_reached = true;
4949
return false;
5050
}
51-
eof_reached = (i == 0);
52-
lines = string(buf, buf + i);
51+
eof_reached = false;
52+
string new_lines(buf, buf + i);
53+
lines += new_lines;
5354
return true;
5455
}

u11_testat/SocketIO.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ class SocketIO {
2525
void writeN(const char *buf, int len);
2626
void doClose();
2727
std::string getPeerInfo();
28+
void closeReadSocket();
2829
private:
2930
int sock; // socket file descriptor
3031
char buf[BUF_SIZE]; // a bit stupid way to mimick an istream

u11_testat/htechoserv.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@ string generateResponse(string request, string clintinfo, int counter) {
3737
"<div>This is request <b>#" << counter << "</b>.</div>" <<
3838
"<div>This is your request:</div>" <<
3939
"<pre>" << request << "</pre>" <<
40-
"</body></html>\n";
40+
"<form action=\"input_file.htm\" method=\"post\" enctype=\"multipart/form-data\">" <<
41+
"File upload test: <input name=\"Datei\" type=\"file\" /><input type=\"submit\" />" <<
42+
"</form>" << "</body></html>\n";
4143
ss2 << getHeaders(ss1.str().length()) << ss1.str();
4244
return ss2.str();
4345
}
@@ -74,16 +76,17 @@ int main(int argc, char**argv) {
7476
SocketIO sio(clientfd);
7577
cout << "Connected to " << sio.getPeerInfo() << endl;
7678
string lines_received = sio.readlines();
79+
sio.closeReadSocket();
7780
if (quitRequested(lines_received)) {
7881
cout << endl << endl;
7982
quit = true;
8083
}
8184
string reply = generateResponse(lines_received, sio.getPeerInfo(), counter);
82-
sleep(5);
85+
//sleep(5);
8386
sio.writeN(reply.c_str(), reply.length());
8487
sio.doClose();
8588

86-
cout << "Request done!" << endl << endl;
89+
cout << "*** Request done ***" << endl << endl;
8790
if (quit) {
8891
cout << "******************************" << endl;
8992
cout << "* SERVER IS SHUTTING DOWN!!! *" << endl;

0 commit comments

Comments
 (0)