int main(int argc, char *argv[]) { char *host, *filename; int port; int clientfd; if (argc != 4) { fprintf(stderr, "Usage: %s <host> <port> <filename>\n", argv[0]); exit(1); } host = argv[1]; port = atoi(argv[2]); filename = argv[3]; /* Open a single connection to the specified host and port */ int i; for(i=0;i<5;i++){ clientfd = Open_clientfd(host, port); clientSend(clientfd, filename); clientPrint(clientfd); Close(clientfd); } exit(0); }
int main(int argc, char *argv[]) { char *host, *filename; int port; int clientfd; int runs; if (argc != 5) { fprintf(stderr, "Usage: %s <host> <port> <filename> <runs>\n", argv[0]); exit(1); } host = argv[1]; port = atoi(argv[2]); filename = argv[3]; //runs = atoi(argv[4]); /* Open a single connection to the specified host and port */ printf("host: %s port: %d filename: %s runs: %d\n", host, port, filename, runs); clientfd = Open_clientfd(host, port); clientSend(clientfd, filename); clientPrint(clientfd); Close(clientfd); exit(0); }
void* workers(void* _filename){ char* filename = (char*) _filename; //printf("file:%s\n", filename); int clientfd = Open_clientfd("localhost", 8559); clientSend(clientfd, filename); clientPrint(clientfd); Close(clientfd); return NULL; }
static int clientPrintf(int client, const char* format, ...) { char buffer[1024]; va_list ap; va_start(ap, format); vsnprintf(buffer, 1023, format, ap); va_end(ap); buffer[1023] = 0; return clientPrint(client, buffer); }
int main(int argc, char **argv) { int err; parseArguments(argc, argv); if (nodaemon == 0) { err = daemonise(); if (err != 0) exit(1); err = writePidFile(pidFile); if (err != 0) exit(1); } err = signalisation(); if (err != 0) exit(1); serverSocket = openServerSocket(port); if (serverSocket == -1) exit(1); request_t req; response_t resp; output_t output; memset(&output, 0, sizeof(output_t)); while (serverSocket != -1) { memset(&req, 0, sizeof(request_t)); memset(&resp, 0, sizeof(response_t)); int client = serverSocketAccept(serverSocket); if (client == -1) continue; int r = parseRequest(client, &req, &resp); if (r != 0) { clientPrintf(client, "HTTP/1.1 %03d\r\n", resp.status); closeClient(client); continue; } if (1) { printf("path: %s\n", req.path); for (int i =0; i < req.num_args; i++) printf("arg[%d]: %s = %s\n", i, req.names[i], req.values[i]); } const char* cmdline = findCommand(req.path); if (cmdline == NULL) { log_warn("Daemon: Invalid path: '%s'\n", req.path); clientPrint(client, "HTTP/1.1 404\r\n"); closeClient(client); continue; } if (execute(&output, cmdline) != 0) { clientPrint(client, "HTTP/1.1 500\r\n"); // Internal server error closeClient(client); continue; } if ((output.count > 8) && (strncmp(output.buf, "HTTP/1.1", 8) == 0)) { clientWrite(client, output.buf, output.count); } else { clientPrintf(client, "HTTP/1.1 200\r\nContent-Length: %d\r\n\r\n", output.count); clientWrite(client, output.buf, output.count); } closeClient(client); output_clear(&output); if (req.path) free(req.path); } removePidFile(pidFile); return 0; }