first commit

This commit is contained in:
Jose Caban
2025-06-07 01:59:34 -04:00
commit 388ac241f0
3558 changed files with 9116289 additions and 0 deletions

View File

@@ -0,0 +1,8 @@
D/ezxml////
D/include////
D/pthreads////
/snprintf.c/1.1/Tue Feb 14 00:39:47 2006//
/main.c/1.3/Tue Mar 28 00:07:54 2006//
/networking.c/1.2/Tue Mar 28 00:07:54 2006//
/parser.c/1.2/Tue Mar 28 00:07:54 2006//
/threads.c/1.6/Tue Mar 28 00:07:54 2006//

View File

@@ -0,0 +1,8 @@
D/ezxml///////
D/include///////
D/pthreads///////
/snprintf.c////*///
/main.c////*///
/networking.c////*///
/parser.c////*///
/threads.c////*///

View File

@@ -0,0 +1,8 @@
D/ezxml///////
D/include///////
D/pthreads///////
/snprintf.c////*///
/main.c////*///
/networking.c////*///
/parser.c////*///
/threads.c////*///

View File

@@ -0,0 +1,8 @@
D/ezxml////
D/include////
D/pthreads////
/snprintf.c/1.1/Tue Feb 14 00:39:47 2006//
/main.c/1.2/Thu Mar 9 01:14:39 2006//
/networking.c/1.1/Tue Mar 7 01:00:35 2006//
/parser.c/1.1/Tue Mar 7 01:00:35 2006//
/threads.c/1.1/Tue Mar 7 01:00:35 2006//

View File

@@ -0,0 +1 @@
CS4210/Project 2/client/src

View File

@@ -0,0 +1 @@
:ext:asskoala@192.168.0.3:/usr/_CVS

View File

@@ -0,0 +1,3 @@
/ezxml.c/1.1/Tue Feb 14 01:54:26 2006//
/ezxml.h/1.1/Tue Feb 14 00:39:47 2006//
D

View File

@@ -0,0 +1,2 @@
/ezxml.c////*///
/ezxml.h////*///

View File

@@ -0,0 +1,2 @@
/ezxml.c////*///
/ezxml.h////*///

View File

@@ -0,0 +1,3 @@
/ezxml.c/0/dummy timestamp//
/ezxml.h/0/dummy timestamp//
D

View File

@@ -0,0 +1 @@
CS4210/Project 2/client/src/ezxml

View File

@@ -0,0 +1 @@
:ext:asskoala@192.168.0.3:/usr/_CVS

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,157 @@
/* ezxml.h
*
* Copyright 2004, 2005 Aaron Voisine <aaron@voisine.org>
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef _EZXML_H
#define _EZXML_H
#include <stdlib.h>
#include <stdio.h>
#include <stdarg.h>
#include <fcntl.h>
#ifdef __cplusplus
extern "C" {
#endif
#define EZXML_BUFSIZE 1024 // size of internal memory buffers
#define EZXML_NAMEM 0x80 // name is malloced
#define EZXML_TXTM 0x40 // txt is malloced
#define EZXML_DUP 0x20 // attribute name and value are strduped
typedef struct ezxml *ezxml_t;
struct ezxml {
char *name; // tag name
char **attr; // tag attributes { name, value, name, value, ... NULL }
char *txt; // tag character content, empty string if none
size_t off; // tag offset from start of parent tag character content
ezxml_t next; // next tag with same name in this section at this depth
ezxml_t sibling; // next tag with different name in same section and depth
ezxml_t ordered; // next tag, same section and depth, in original order
ezxml_t child; // head of sub tag list, NULL if none
ezxml_t parent; // parent tag, NULL if current tag is root tag
short flags; // additional information
};
// Given a string of xml data and its length, parses it and creates an ezxml
// structure. For efficiency, modifies the data by adding null terminators
// and decoding ampersand sequences. If you don't want this, copy the data and
// pass in the copy. Returns NULL on failure.
ezxml_t ezxml_parse_str(char *s, size_t len);
// A wrapper for ezxml_parse_str() that accepts a file descriptor. First
// attempts to mem map the file. Failing that, reads the file into memory.
// Returns NULL on failure.
ezxml_t ezxml_parse_fd(int fd);
// a wrapper for ezxml_parse_fd() that accepts a file name
ezxml_t ezxml_parse_file(const char *file);
// Wrapper for ezxml_parse_str() that accepts a file stream. Reads the entire
// stream into memory and then parses it. For xml files, use ezxml_parse_file()
// or ezxml_parse_fd()
ezxml_t ezxml_parse_fp(FILE *fp);
// returns the first child tag (one level deeper) with the given name or NULL
// if not found
ezxml_t ezxml_child(ezxml_t xml, const char *name);
// returns the next tag of the same name in the same section and depth or NULL
// if not found
#define ezxml_next(xml) ((xml) ? xml->next : NULL)
// Returns the Nth tag with the same name in the same section at the same depth
// or NULL if not found. An index of 0 returns the tag given.
ezxml_t ezxml_idx(ezxml_t xml, int idx);
// returns the name of the given tag
#define ezxml_name(xml) ((xml) ? xml->name : NULL)
// returns the given tag's character content or empty string if none
#define ezxml_txt(xml) ((xml) ? xml->txt : "")
// returns the value of the requested tag attribute, or NULL if not found
const char *ezxml_attr(ezxml_t xml, const char *attr);
// Traverses the ezxml sturcture to retrieve a specific subtag. Takes a
// variable length list of tag names and indexes. The argument list must be
// terminated by either an index of -1 or an empty string tag name. Example:
// title = ezxml_get(library, "shelf", 0, "book", 2, "title", -1);
// This retrieves the title of the 3rd book on the 1st shelf of library.
// Returns NULL if not found.
ezxml_t ezxml_get(ezxml_t xml, ...);
// Converts an ezxml structure back to xml. Returns a string of xml data that
// must be freed.
char *ezxml_toxml(ezxml_t xml);
// returns a NULL terminated array of processing instructions for the given
// target
const char **ezxml_pi(ezxml_t xml, const char *target);
// frees the memory allocated for an ezxml structure
void ezxml_free(ezxml_t xml);
// returns parser error message or empty string if none
const char *ezxml_error(ezxml_t xml);
// returns a new empty ezxml structure with the given root tag name
ezxml_t ezxml_new(const char *name);
// wrapper for ezxml_new() that strdup()s name
#define ezxml_new_d(name) ezxml_set_flag(ezxml_new(strdup(name)), EZXML_NAMEM)
// Adds a child tag. off is the offset of the child tag relative to the start
// of the parent tag's character content. Returns the child tag.
ezxml_t ezxml_add_child(ezxml_t xml, const char *name, size_t off);
// wrapper for ezxml_add_child() that strdup()s name
#define ezxml_add_child_d(xml, name, off) \
ezxml_set_flag(ezxml_add_child(xml, strdup(name), off), EZXML_NAMEM)
// sets the character content for the given tag and returns the tag
ezxml_t ezxml_set_txt(ezxml_t xml, const char *txt);
// wrapper for ezxml_set_txt() that strdup()s txt
#define ezxml_set_txt_d(xml, txt) \
ezxml_set_flag(ezxml_set_txt(xml, strdup(txt)), EZXML_TXTM)
// Sets the given tag attribute or adds a new attribute if not found. A value
// of NULL will remove the specified attribute.
void ezxml_set_attr(ezxml_t xml, const char *name, const char *value);
// Wrapper for ezxml_set_attr() that strdup()s name/value. Value cannot be NULL
#define ezxml_set_attr_d(xml, name, value) \
ezxml_set_attr(ezxml_set_flag(xml, EZXML_DUP), strdup(name), strdup(value))
// sets a flag for the given tag and returns the tag
ezxml_t ezxml_set_flag(ezxml_t xml, short flag);
// removes a tag along with all its subtags
void ezxml_remove(ezxml_t xml);
#ifdef __cplusplus
}
#endif
#endif // _EZXML_H

View File

@@ -0,0 +1,7 @@
/snprintf.h/1.1/Tue Feb 14 00:39:47 2006//
/test.h/1.1/Fri Feb 17 23:35:17 2006//
/defs.h/1.1/Tue Mar 7 01:00:37 2006//
/networking.h/1.1/Tue Mar 7 01:00:37 2006//
/parser.h/1.1/Tue Mar 7 01:00:37 2006//
/threads.h/1.1/Tue Mar 7 01:00:37 2006//
D

View File

@@ -0,0 +1,6 @@
/snprintf.h////*///
/test.h////*///
/defs.h////*///
/networking.h////*///
/parser.h////*///
/threads.h////*///

View File

@@ -0,0 +1,2 @@
/snprintf.h////*///
/test.h////*///

View File

@@ -0,0 +1,3 @@
/snprintf.h/1.1/Tue Feb 14 00:39:47 2006//
/test.h/1.1/Fri Feb 17 23:35:17 2006//
D

View File

@@ -0,0 +1 @@
CS4210/Project 2/client/src/include

View File

@@ -0,0 +1 @@
:ext:asskoala@192.168.0.3:/usr/_CVS

View File

@@ -0,0 +1,15 @@
#ifndef _DEFS_H_
#define _DEFS_H_
/* Turn off deprecation warnings to avoid use of "safe" strings in Win32 */
#define _CRT_SECURE_NO_DEPRECATE 1
#define _CRT_NONSTDC_NO_DEPRECATE 1
#define HTTP_REQUEST_SIZE 2024
#define RECV_SIZE 64
#define timenormal(sec,usec) if(0>usec){sec--; usec+=1000000;}
#define DieWithError(msg) { \
fprintf(stderr, "%s: PwnT! Error on line %d.\n", (msg), __LINE__); \
perror(msg); \
exit(EXIT_FAILURE);}
#endif

View File

@@ -0,0 +1,11 @@
#ifndef _NETWORKING_H_
#define _NETWORKING_H_
/*
* Open a TCP Socket connection with:
* ipaddr: Remote IP Address
* server_port: Port to open on
*/
int createTCPSocket(char *ipaddr, unsigned short server_port);
#endif

View File

@@ -0,0 +1,16 @@
#ifndef _PARSER_H_
#define _PARSER_H_
#include "test.h"
/*
* Parse the Tests from the testFile
*/
int parseTests(Test** testListPtr, char* fileName);
/*
* Print the tests that were read in
*/
void printTests(Test* testList, int count);
#endif

View File

@@ -0,0 +1,29 @@
#ifndef _PORTABLE_SNPRINTF_H_
#define _PORTABLE_SNPRINTF_H_
#define PORTABLE_SNPRINTF_VERSION_MAJOR 2
#define PORTABLE_SNPRINTF_VERSION_MINOR 2
#include <stddef.h>
#include <stdarg.h>
#ifdef HAVE_SNPRINTF
#include <stdio.h>
#else
extern int snprintf(char *, size_t, const char *, /*args*/ ...);
extern int vsnprintf(char *, size_t, const char *, va_list);
#endif
#if defined(HAVE_SNPRINTF) && defined(PREFER_PORTABLE_SNPRINTF)
extern int portable_snprintf(char *str, size_t str_m, const char *fmt, /*args*/ ...);
extern int portable_vsnprintf(char *str, size_t str_m, const char *fmt, va_list ap);
#define snprintf portable_snprintf
#define vsnprintf portable_vsnprintf
#endif
extern int asprintf (char **ptr, const char *fmt, /*args*/ ...);
extern int vasprintf (char **ptr, const char *fmt, va_list ap);
extern int asnprintf (char **ptr, size_t str_m, const char *fmt, /*args*/ ...);
extern int vasnprintf(char **ptr, size_t str_m, const char *fmt, va_list ap);
#endif

View File

@@ -0,0 +1,20 @@
#ifndef _TEST_H_
#define _TEST_H_
typedef struct {
char** fileList;
char* name;
int numThreads;
int iterations;
int fileCount;
} Test;
typedef struct {
char *fileName;
char *hostName;
unsigned short port_number;
int iterations;
} Request;
#endif

View File

@@ -0,0 +1,9 @@
#ifndef _THREADS_H_
#define _THREADS_H_
#include "test.h"
void init_threads(int numThreads, Request** rList, int numFiles);
extern int threads;
#endif

View File

@@ -0,0 +1,60 @@
// ANSI C89 Stuff
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
// l33t_client Stuff
#include "include/test.h"
#include "include/parser.h"
#include "include/networking.h"
#include "include/defs.h"
/*
* l33t_client Main, builds Requests and sends them to the threads
*/
int main(int argc, char** argv) {
Test* testList = NULL;
int numTests;
int i, j, k;
Request *r = malloc(sizeof(Request));
Request **rList = NULL;
// Scan command line
if (argc < 3) {
printf("Improper usage\n");
printf(" ./l33t_client IP_ADDRESS PORT_NUM TESTFILE\n");
return EXIT_SUCCESS;
} else {
r->hostName = argv[1];
r->port_number = atoi(argv[2]);
printf("Accessing %s:%d\n",r->hostName, r->port_number);
fflush(stdout);
}
numTests = parseTests(&testList, (argc > 3) ? argv[3] : "testFile.xml");
// Create the requests
for (i=0; i<testList[0].fileCount; i++) {
rList = realloc(rList, sizeof(Request*)*(i+1));
rList[i] = malloc(sizeof(Request));
memcpy(rList[i], r, sizeof(Request));
rList[i]->fileName = testList[0].fileList[i];
rList[i]->iterations = testList[0].iterations;
}
// TODO: Alter this such that the threads wait
init_threads(testList[0].numThreads, rList, testList[0].fileCount);
printf(" fileName | iterations | diff_secs | diff_usecs | sock fails | total_bytes_recv\n");
// TODO: Wait for threads to exit properly
for(;getchar()!='q';) {
}
return EXIT_SUCCESS;
}

View File

@@ -0,0 +1,44 @@
#include "include/networking.h"
#include "include/defs.h"
//C89 stuff
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
//Networking Stuff
#ifdef _WIN32
#include <winsock.h>
#else
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#endif
int createTCPSocket(char *ipaddr, unsigned short server_port)
{
int sock; /* Socket descriptor */
struct sockaddr_in ServAddr; /* Address Structure */
#ifdef _WIN32
WSADATA wsaData; /* Winsock struct. */
if (WSAStartup(MAKEWORD(2, 0), &wsaData) != 0)/* Winsock 2.0 DLL. */
DieWithError("WSAStartup() failed");
#endif
if((sock = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0)
DieWithError("socket() failed");
memset(&ServAddr, 0, sizeof(ServAddr));
ServAddr.sin_family = AF_INET;
ServAddr.sin_addr.s_addr = inet_addr(ipaddr);
ServAddr.sin_port = htons(server_port);
if (connect(sock, (struct sockaddr *) &ServAddr, sizeof(ServAddr)) < 0) {
return -1;
} else {
return sock;
}
}

View File

@@ -0,0 +1,91 @@
#include "include/parser.h"
#include "include/test.h"
#include "ezxml/ezxml.h"
#include <stdio.h>
#include <string.h>
int parseTests(Test** testListPtr, char* fileName) {
ezxml_t xmlFile = ezxml_parse_file(fileName);
ezxml_t current;
Test* testList;
int index;
if (!xmlFile) {
printf("Couldn't load testFile.xml\n");
exit(1);
}
current = xmlFile->child;
for (index = 0 ;current; index++, current = current->sibling ) {
ezxml_t child;
*testListPtr = realloc(*testListPtr, (index+1)*sizeof(Test));
testList = *testListPtr;
//No Checks!!!! Buffer Overflow capable!!!!
testList[index].name = malloc(sizeof(char)*(strlen(current->name)+1));
strcpy(testList[index].name, current->name);
for (child = current->child; child; child = child->sibling ) {
if (!strcmp(child->name,"numthreads")) {
testList[index].numThreads = atoi(child->txt);
} else if (!strcmp(child->name, "iterations")) {
testList[index].iterations = atoi(child->txt);
} else if (!strcmp(child->name, "filesToRetrieve")) {
ezxml_t files = child->child;
int* fileCount = &(testList[index].fileCount);
*fileCount = 0;
testList[index].fileList = NULL;
while (files) {
//Increase length of flleList
testList[index].fileList
= realloc(testList[index].fileList
, sizeof(char*) * (*fileCount+1));
//Allocate space for contents
testList[index].fileList[*fileCount]
= malloc(sizeof(char) * (strlen(files->txt)+1));
//Copy contents into structure
strcpy(testList[index].fileList[*fileCount], files->txt);
files = files->next;
(*fileCount)++;
}
}
} // end while(child)
} //end for(current)
ezxml_free(xmlFile);
return index;
}
void printTests(Test* testList, int count) {
int index;
for (index = 0; index < count; index++) {
printf("\n-- Test: %s \n", testList[index].name);
printf("--- number of threads: %d \n",
testList[index].numThreads);
printf("--- number of iterations: %d \n",
testList[index].iterations);
{
int i;
for (i=0; i<testList[index].fileCount; i++) {
printf("--- Load File: %s \n",
testList[index].fileList[i]);
}
}
}
}

View File

@@ -0,0 +1,2 @@
D/include////
D/lib////

View File

@@ -0,0 +1,2 @@
D/include///////
D/lib///////

View File

@@ -0,0 +1 @@
D

View File

@@ -0,0 +1 @@
CS4210/Project 2/client/src/pthreads

View File

@@ -0,0 +1 @@
:ext:asskoala@192.168.0.3:/usr/_CVS

View File

@@ -0,0 +1,4 @@
/pthread.h/1.1/Tue Feb 14 04:11:37 2006//
/sched.h/1.1/Tue Feb 14 04:11:37 2006//
/semaphore.h/1.1/Tue Feb 14 04:11:37 2006//
D

View File

@@ -0,0 +1,3 @@
/pthread.h////*///
/sched.h////*///
/semaphore.h////*///

View File

@@ -0,0 +1,3 @@
/pthread.h////*///
/sched.h////*///
/semaphore.h////*///

View File

@@ -0,0 +1,4 @@
/pthread.h/0/dummy timestamp//
/sched.h/0/dummy timestamp//
/semaphore.h/0/dummy timestamp//
D

View File

@@ -0,0 +1 @@
CS4210/Project 2/client/src/pthreads/include

View File

@@ -0,0 +1 @@
:ext:asskoala@192.168.0.3:/usr/_CVS

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,178 @@
/*
* Module: sched.h
*
* Purpose:
* Provides an implementation of POSIX realtime extensions
* as defined in
*
* POSIX 1003.1b-1993 (POSIX.1b)
*
* --------------------------------------------------------------------------
*
* Pthreads-win32 - POSIX Threads Library for Win32
* Copyright(C) 1998 John E. Bossom
* Copyright(C) 1999,2005 Pthreads-win32 contributors
*
* Contact Email: rpj@callisto.canberra.edu.au
*
* The current list of contributors is contained
* in the file CONTRIBUTORS included with the source
* code distribution. The list can also be seen at the
* following World Wide Web location:
* http://sources.redhat.com/pthreads-win32/contributors.html
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library in the file COPYING.LIB;
* if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#ifndef _SCHED_H
#define _SCHED_H
#undef PTW32_LEVEL
#if defined(_POSIX_SOURCE)
#define PTW32_LEVEL 0
/* Early POSIX */
#endif
#if defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE >= 199309
#undef PTW32_LEVEL
#define PTW32_LEVEL 1
/* Include 1b, 1c and 1d */
#endif
#if defined(INCLUDE_NP)
#undef PTW32_LEVEL
#define PTW32_LEVEL 2
/* Include Non-Portable extensions */
#endif
#define PTW32_LEVEL_MAX 3
#if !defined(PTW32_LEVEL)
#define PTW32_LEVEL PTW32_LEVEL_MAX
/* Include everything */
#endif
#if __GNUC__ && ! defined (__declspec)
# error Please upgrade your GNU compiler to one that supports __declspec.
#endif
/*
* When building the DLL code, you should define PTW32_BUILD so that
* the variables/functions are exported correctly. When using the DLL,
* do NOT define PTW32_BUILD, and then the variables/functions will
* be imported correctly.
*/
#ifndef PTW32_STATIC_LIB
# ifdef PTW32_BUILD
# define PTW32_DLLPORT __declspec (dllexport)
# else
# define PTW32_DLLPORT __declspec (dllimport)
# endif
#else
# define PTW32_DLLPORT
#endif
/*
* This is a duplicate of what is in the autoconf config.h,
* which is only used when building the pthread-win32 libraries.
*/
#ifndef PTW32_CONFIG_H
# if defined(WINCE)
# define NEED_ERRNO
# define NEED_SEM
# endif
# if defined(_UWIN) || defined(__MINGW32__)
# define HAVE_MODE_T
# endif
#endif
/*
*
*/
#if PTW32_LEVEL >= PTW32_LEVEL_MAX
#ifdef NEED_ERRNO
#include "need_errno.h"
#else
#include <errno.h>
#endif
#endif /* PTW32_LEVEL >= PTW32_LEVEL_MAX */
#if defined(__MINGW32__) || defined(_UWIN)
#if PTW32_LEVEL >= PTW32_LEVEL_MAX
/* For pid_t */
# include <sys/types.h>
/* Required by Unix 98 */
# include <time.h>
#endif /* PTW32_LEVEL >= PTW32_LEVEL_MAX */
#else
typedef int pid_t;
#endif
/* Thread scheduling policies */
enum {
SCHED_OTHER = 0,
SCHED_FIFO,
SCHED_RR,
SCHED_MIN = SCHED_OTHER,
SCHED_MAX = SCHED_RR
};
struct sched_param {
int sched_priority;
};
#ifdef __cplusplus
extern "C"
{
#endif /* __cplusplus */
PTW32_DLLPORT int __cdecl sched_yield (void);
PTW32_DLLPORT int __cdecl sched_get_priority_min (int policy);
PTW32_DLLPORT int __cdecl sched_get_priority_max (int policy);
PTW32_DLLPORT int __cdecl sched_setscheduler (pid_t pid, int policy);
PTW32_DLLPORT int __cdecl sched_getscheduler (pid_t pid);
/*
* Note that this macro returns ENOTSUP rather than
* ENOSYS as might be expected. However, returning ENOSYS
* should mean that sched_get_priority_{min,max} are
* not implemented as well as sched_rr_get_interval.
* This is not the case, since we just don't support
* round-robin scheduling. Therefore I have chosen to
* return the same value as sched_setscheduler when
* SCHED_RR is passed to it.
*/
#define sched_rr_get_interval(_pid, _interval) \
( errno = ENOTSUP, (int) -1 )
#ifdef __cplusplus
} /* End of extern "C" */
#endif /* __cplusplus */
#undef PTW32_LEVEL
#undef PTW32_LEVEL_MAX
#endif /* !_SCHED_H */

View File

@@ -0,0 +1,166 @@
/*
* Module: semaphore.h
*
* Purpose:
* Semaphores aren't actually part of the PThreads standard.
* They are defined by the POSIX Standard:
*
* POSIX 1003.1b-1993 (POSIX.1b)
*
* --------------------------------------------------------------------------
*
* Pthreads-win32 - POSIX Threads Library for Win32
* Copyright(C) 1998 John E. Bossom
* Copyright(C) 1999,2005 Pthreads-win32 contributors
*
* Contact Email: rpj@callisto.canberra.edu.au
*
* The current list of contributors is contained
* in the file CONTRIBUTORS included with the source
* code distribution. The list can also be seen at the
* following World Wide Web location:
* http://sources.redhat.com/pthreads-win32/contributors.html
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library in the file COPYING.LIB;
* if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#if !defined( SEMAPHORE_H )
#define SEMAPHORE_H
#undef PTW32_LEVEL
#if defined(_POSIX_SOURCE)
#define PTW32_LEVEL 0
/* Early POSIX */
#endif
#if defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE >= 199309
#undef PTW32_LEVEL
#define PTW32_LEVEL 1
/* Include 1b, 1c and 1d */
#endif
#if defined(INCLUDE_NP)
#undef PTW32_LEVEL
#define PTW32_LEVEL 2
/* Include Non-Portable extensions */
#endif
#define PTW32_LEVEL_MAX 3
#if !defined(PTW32_LEVEL)
#define PTW32_LEVEL PTW32_LEVEL_MAX
/* Include everything */
#endif
#if __GNUC__ && ! defined (__declspec)
# error Please upgrade your GNU compiler to one that supports __declspec.
#endif
/*
* When building the DLL code, you should define PTW32_BUILD so that
* the variables/functions are exported correctly. When using the DLL,
* do NOT define PTW32_BUILD, and then the variables/functions will
* be imported correctly.
*/
#ifndef PTW32_STATIC_LIB
# ifdef PTW32_BUILD
# define PTW32_DLLPORT __declspec (dllexport)
# else
# define PTW32_DLLPORT __declspec (dllimport)
# endif
#else
# define PTW32_DLLPORT
#endif
/*
* This is a duplicate of what is in the autoconf config.h,
* which is only used when building the pthread-win32 libraries.
*/
#ifndef PTW32_CONFIG_H
# if defined(WINCE)
# define NEED_ERRNO
# define NEED_SEM
# endif
# if defined(_UWIN) || defined(__MINGW32__)
# define HAVE_MODE_T
# endif
#endif
/*
*
*/
#if PTW32_LEVEL >= PTW32_LEVEL_MAX
#ifdef NEED_ERRNO
#include "need_errno.h"
#else
#include <errno.h>
#endif
#endif /* PTW32_LEVEL >= PTW32_LEVEL_MAX */
#define _POSIX_SEMAPHORES
#ifdef __cplusplus
extern "C"
{
#endif /* __cplusplus */
#ifndef HAVE_MODE_T
typedef unsigned int mode_t;
#endif
typedef struct sem_t_ * sem_t;
PTW32_DLLPORT int __cdecl sem_init (sem_t * sem,
int pshared,
unsigned int value);
PTW32_DLLPORT int __cdecl sem_destroy (sem_t * sem);
PTW32_DLLPORT int __cdecl sem_trywait (sem_t * sem);
PTW32_DLLPORT int __cdecl sem_wait (sem_t * sem);
PTW32_DLLPORT int __cdecl sem_timedwait (sem_t * sem,
const struct timespec * abstime);
PTW32_DLLPORT int __cdecl sem_post (sem_t * sem);
PTW32_DLLPORT int __cdecl sem_post_multiple (sem_t * sem,
int count);
PTW32_DLLPORT int __cdecl sem_open (const char * name,
int oflag,
mode_t mode,
unsigned int value);
PTW32_DLLPORT int __cdecl sem_close (sem_t * sem);
PTW32_DLLPORT int __cdecl sem_unlink (const char * name);
PTW32_DLLPORT int __cdecl sem_getvalue (sem_t * sem,
int * sval);
#ifdef __cplusplus
} /* End of extern "C" */
#endif /* __cplusplus */
#undef PTW32_LEVEL
#undef PTW32_LEVEL_MAX
#endif /* !SEMAPHORE_H */

View File

@@ -0,0 +1,7 @@
/pthreadGC2.dll/1.1/Tue Feb 14 04:11:37 2006/-kb/
/pthreadGCE2.dll/1.1/Tue Feb 14 04:11:37 2006/-kb/
/pthreadVC2.dll/1.1/Tue Feb 14 04:11:37 2006/-kb/
/pthreadVC2.lib/1.1/Tue Feb 14 04:11:37 2006/-kb/
/pthreadVSE2.dll/1.1/Tue Feb 14 04:11:37 2006/-kb/
/pthreadVSE2.lib/1.1/Tue Feb 14 04:11:37 2006/-kb/
D

View File

@@ -0,0 +1,6 @@
/pthreadGC2.dll////*///
/pthreadGCE2.dll////*///
/pthreadVC2.dll////*///
/pthreadVC2.lib////*///
/pthreadVSE2.dll////*///
/pthreadVSE2.lib////*///

View File

@@ -0,0 +1,6 @@
/pthreadGC2.dll////*///
/pthreadGCE2.dll////*///
/pthreadVC2.dll////*///
/pthreadVC2.lib////*///
/pthreadVSE2.dll////*///
/pthreadVSE2.lib////*///

View File

@@ -0,0 +1,7 @@
/pthreadGC2.dll/0/dummy timestamp/-kb/
/pthreadGCE2.dll/0/dummy timestamp/-kb/
/pthreadVC2.dll/0/dummy timestamp/-kb/
/pthreadVC2.lib/0/dummy timestamp/-kb/
/pthreadVSE2.dll/0/dummy timestamp/-kb/
/pthreadVSE2.lib/0/dummy timestamp/-kb/
D

View File

@@ -0,0 +1 @@
CS4210/Project 2/client/src/pthreads/lib

View File

@@ -0,0 +1 @@
:ext:asskoala@192.168.0.3:/usr/_CVS

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,126 @@
#include "include/threads.h"
#include "include/defs.h"
#include "include/networking.h"
#include "include/test.h"
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <sys/time.h>
int threads = 0;
char ready;
void *makeRequest(void *in) {
int i;
int sock_fail=0;
int total_bytes_received;
int sendlen;
char http_request[HTTP_REQUEST_SIZE];
Request *r = (Request*)in;
long diff_secs, diff_usecs;
struct timeval tv;
struct timezone tz;
//Detach thread
pthread_detach(pthread_self());
while(ready != 1);
//printf("Thread %d starting\n", pthread_self());
//Timing stuff
gettimeofday(&tv, &tz);
diff_secs = tv.tv_sec;
diff_usecs = tv.tv_usec;
for (i=0, sock_fail=0; i < r->iterations; i++) {
int sock;
for(;;){
sock = createTCPSocket(r->hostName, r->port_number);
if(sock<0) {
sock_fail++;
continue;
} else {
break;
}
}
memset(http_request, 0, sizeof(char)*HTTP_REQUEST_SIZE);
sprintf(http_request, "GET %s HTTP/1.1\r\n\r\n\0" , r->fileName);
sendlen=strlen(http_request) + 1;
// printf("Requesting: %s\n", http_request);
if(send(sock, http_request, sendlen, 0) != sendlen)
{
DieWithError("send() failed");
}
{
int bytes_received = 0;
char get_buffer[RECV_SIZE];
total_bytes_received=0;
for(;;) {
memset(get_buffer, 0, sizeof(char)*RECV_SIZE);
bytes_received = recv(sock, get_buffer, RECV_SIZE, 0);
/* printf("Bytes gotten: %d\n", bytes_received); */
if(bytes_received < 0) {
continue;
} else if (bytes_received == 0) {
break;
} else {
total_bytes_received += bytes_received;
}
}
}
#ifdef _WIN32
closesocket(sock);
#else
close(sock);
#endif
// printf("Finished receiving File.\n");
}
gettimeofday(&tv, &tz);
diff_secs = tv.tv_sec - diff_secs;
diff_usecs = tv.tv_usec - diff_usecs;
timenormal(diff_secs,diff_usecs)
printf("%s, %d, %ld, %ld, %d, %d\n",r->fileName, r->iterations,
diff_secs, diff_usecs, sock_fail,
total_bytes_received);
fflush(stdout);
return NULL;
}
void init_threads(int numThreads, Request** rList, int numFiles) {
int i, j;
ready = 0;
for (i=0, j=0; i < numThreads; i++, j++) {
if (j >= numFiles) {
j = 0;
}
pthread_create(malloc(sizeof(pthread_t)),NULL,makeRequest,rList[j]);
}
ready = 1;
}