diff options
author | Matt Strapp <strap012@umn.edu> | 2020-12-06 18:23:18 -0600 |
---|---|---|
committer | Matt Strapp <strap012@umn.edu> | 2020-12-06 18:23:18 -0600 |
commit | f5e8f7b01168033ed20686d084fe3a9c94892c5c (patch) | |
tree | ef73e80b1447a99b0ea0fa9d48e6fa28769a6937 | |
parent | I AM A MORON (diff) | |
download | csci4061-f5e8f7b01168033ed20686d084fe3a9c94892c5c.tar csci4061-f5e8f7b01168033ed20686d084fe3a9c94892c5c.tar.gz csci4061-f5e8f7b01168033ed20686d084fe3a9c94892c5c.tar.bz2 csci4061-f5e8f7b01168033ed20686d084fe3a9c94892c5c.tar.lz csci4061-f5e8f7b01168033ed20686d084fe3a9c94892c5c.tar.xz csci4061-f5e8f7b01168033ed20686d084fe3a9c94892c5c.tar.zst csci4061-f5e8f7b01168033ed20686d084fe3a9c94892c5c.zip |
oops
-rw-r--r-- | P4/util.c | 26 |
1 files changed, 6 insertions, 20 deletions
@@ -29,7 +29,7 @@ int sockfd; - if init encounters any errors, it will call exit(). ************************************************/ void init(int port) { - if ((sockfd = socket(PF_INET, SOCK_STREAM, 0)) == -1) { + if ((sockfd = socket(AF_INET, SOCK_STREAM, 0)) == -1) { perror("Cannot create socket"); exit(EXIT_FAILURE); } @@ -93,13 +93,11 @@ int accept_connection(void) { specific 'connection'. ************************************************/ int get_request(int fd, char *filename) { - printf("%d\n", fd); char buffer[2048] = "\0"; char get[100], http[100]; - read(fd, buffer, 2048); - printf("%s\n", buffer); + recv(fd, buffer, 2048, 0); if(sscanf(buffer, "%s %s %s", get, filename, http) < 2) { // Read HTTP Get request and parse close(fd); return -1; @@ -145,7 +143,6 @@ int get_request(int fd, char *filename) { ************************************************/ int return_result(int fd, char *content_type, char *buf, int numbytes) { //Convert low IO to high IO - printf("%d\n", fd); FILE *fdstream = fdopen(fd, "w"); if (fdstream == NULL) { printf("File stream conversion(?) failed.\n"); @@ -161,13 +158,8 @@ int return_result(int fd, char *content_type, char *buf, int numbytes) { close(fd); return -3; } - if (fclose(fdstream) == EOF) { - perror("Stream close error"); - close(fd); - return -4; - } - if (write(fd, buf, numbytes) == -1) { - perror("Bad write"); + if (send(fd, buf, numbytes, 0) == -1) { + perror("Bad send"); close(fd); return -5; } @@ -185,7 +177,6 @@ int return_result(int fd, char *content_type, char *buf, int numbytes) { - returns 0 on success, nonzero on failure. ************************************************/ int return_error(int fd, char *buf) { - printf("%d\n", fd); //Convert low IO to high IO FILE *fdstream = fdopen(fd, "w"); if (fdstream == NULL) { @@ -203,13 +194,8 @@ int return_error(int fd, char *buf) { close(fd); return -3; } - if (fclose(fdstream) == EOF) { - perror("Stream close error"); - close(fd); - return -4; - } - if (write(fd, buf, strlen(buf)) == -1) { - perror("Return result: Write error"); + if (send(fd, buf, strlen(buf), 0) == -1) { + perror("Send error"); close(fd); return -5; } |