Commit 1552e28a authored by Heiko Liermann's avatar Heiko Liermann
Browse files

- bugfix

parent 41c39def
......@@ -28,14 +28,14 @@ int main(int argc, char **argv) {
while(!done) {
//Wo für intressiere ich mich beim select? das wird in readset aufgenommen
//kann ich was von stin oder TCP Verbindung lesen?
FD_SET(0, &rset); //stdin
FD_SET(fd, &rset); //TCP Verbindung
if (stdin_open == 0)
FD_SET(0, &rset); //stdin
//Größter fd +1 , Readset intessiert uns
select(fd + 1, &rset, NULL, NULL, NULL);
//0 ist lesbar, also wenn von stdin was lesbar ist
if (FD_ISSET(0, &rset) && stdin_open == 0) {
if (FD_ISSET(0, &rset)) {
//lese von stdin
len = read(0, (void *) buf, sizeof(buf));
//solange lesen bis stin zuende ist (Strg+D )
......@@ -57,7 +57,7 @@ int main(int argc, char **argv) {
if (len == 0)
done = 1;
else
printf("%.*s", (int)len, buf);
write(1, buf, BUFFER_SIZE);
}
}
......
......@@ -38,7 +38,7 @@ main(int argc, char **argv)
snprintf(buf, sizeof(buf), "%.24s\r\n", ctime(&ticks));
//ctime = converts this integer value into a human-readable string
write(client_fd, buf, strlen(buf));
while (shutdown_wrapper(client_fd, SHUT_RD) > 0);
close_wrapper(client_fd);
//close the coonection with the client call FIN
}
......
......@@ -5,9 +5,9 @@
#include "Socket.h"
int main(int argc, char **argv) {
int i, server_fd, client_fd, nfds, last_array_pos = -1;
int i, server_fd, client_fd, nfds, len;
struct sockaddr_in server_addr;
int client_fds[FD_SETSIZE];
int client_fds[30];
char buf[BUFFER_SIZE];
fd_set read_set, whole_set;
......@@ -27,7 +27,7 @@ int main(int argc, char **argv) {
listen_wrapper(server_fd, LISTENQ);
// fill array with -1
for (i = 0; i < FD_SETSIZE; i++)
for (i = 0; i < 30; i++)
client_fds[i] = -1;
// set the set "whole_set" to zero and after that add the "server_fd" to "read_set"
......@@ -43,30 +43,30 @@ int main(int argc, char **argv) {
if (FD_ISSET(server_fd, &read_set)) {
client_fd = accept_wrapper(server_fd,NULL, NULL);
// safe new clients file descriptor in array
for (i = 0; i < FD_SETSIZE; i++) {
for (i = 0; i < 30; i++) {
if (client_fds[i] < 0) {
client_fds[i] = client_fd;
break;
}
}
if (i == 30)
close_wrapper(client_fd);
// add the new clients file descriptor to the whole set
FD_SET(client_fd, &whole_set);
// if the number of the new clients file descriptor is higher than the actual - update
if (client_fd > nfds)
nfds = client_fd;
// if the iterating index is higher than the last array position - update
if (i > last_array_pos)
last_array_pos = i;
}
// loop through all open file descriptors
for (i = 0; i <= last_array_pos; i++) {
for (i = 0; i < 30; i++) {
if (client_fds[i] < 0)
continue;
// check if picked fd is in the readable set
if (FD_ISSET(client_fds[i], &read_set)) {
// write data into the buffer
recv_wrapper(client_fds[i], buf, BUFFER_SIZE, 0);
// close the connection
do {
len = read(client_fds[i], buf, BUFFER_SIZE, 0);
} while (len > 0);
close_wrapper(client_fds[i]);
FD_CLR(client_fds[i], &whole_set);
client_fds[i] = -1;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment