Commit 95f57d17 authored by Maia Jejelava's avatar Maia Jejelava
Browse files

Comments added.

parent 61cd2235
......@@ -35,19 +35,23 @@ TCP Based Character Generator Service
#include "Socket.h"
//structure for arguments for the thread_handler
struct Args {
int client_fd;
//thread handler that basically just takes client_fd as a parameter
void *thread_handler(void *args) {
char *buf;
//allocate memmory init it with 0
buf = calloc(1, BUFFER_SIZE);
//sets the client_fd to the one that was given by the parameter
int client_fd = ((struct Args *) args)->client_fd;
//sets. An fd_set is a fixed size buffer.
fd_set read, write;
//FD_ZERO() clears a set
......@@ -59,10 +63,10 @@ void *thread_handler(void *args) {
FD_SET(client_fd, &write);
//TODO select_wrapper
//pick one read or wirte connection, double check if the connection is still ready
//pick one read or write connection, double check if the connection is still ready
select(client_fd + 1, &read, &write, 0, 0);
//is client part of read set if so recive
//If the client is part of the read set, then receive
if (FD_ISSET(client_fd, &read)) {
//when all is read
if (recv_wrapper(client_fd, buf, sizeof(buf), 0) == 0) {
......@@ -85,6 +89,7 @@ void *thread_handler(void *args) {
//stop after 72 lines
buf[BUFFER_SIZE - 1] = '\n';
//increase the offset and make sure it doesn't go over 95
offset = offset % 95;
......@@ -10,6 +10,13 @@ int main(int argc, char **argv) {
ssize_t len;
char buf[BUFFER_SIZE];
//getaddrinfo() returns one or more addrinfo structures,
// each of which contains an Internet address that can be specified
// in a call to bind(2) or connect(2). The getaddrinfo() function
// combines the functionality provided by the gethostbyname(3) and
// getservbyname(3) functions into a single interface, but unlike
// the latter functions, getaddrinfo() is reentrant and allows
// programs to eliminate IPv4-versus-IPv6 dependencies.
struct addrinfo *result, hints, *entry;
bzero(&hints, sizeof(hints));
......@@ -5,6 +5,7 @@
#include "Socket.h"
int main(int argc, char* argv[]) {
//Structure to contain information about address of a service provider.
struct addrinfo *result, *entry;
if (argc != 2) {
......@@ -15,7 +16,7 @@ int main(int argc, char* argv[]) {
int ret;
if ((ret = getaddrinfo(argv[1], NULL, NULL, &result))) {
fprintf(stderr, "Getaddrinfo: %s\n", gai_strerror(ret_val));
return 2;
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