コード例 #1
0
 void LodWorkQueueWorker::addRequestToQueue( LodConfig& lodConfig, LodCollapseCostPtr& cost, LodDataPtr& data, LodInputProviderPtr& input, LodOutputProviderPtr& output, LodCollapserPtr& collapser )
 {
     LodWorkQueueRequest* req = new LodWorkQueueRequest();
     req->config = lodConfig;
     req->cost = cost;
     req->data = data;
     req->input = input;
     req->output = output;
     req->collapser = collapser;
     addRequestToQueue(req);
 }
コード例 #2
0
ファイル: myhttpd.c プロジェクト: devarshi150790/Project-OS1
void *accept_request(void *sockid){

struct sockaddr_in client_addr;
unsigned clientLength;
int cSockfd;
int nThreads;
char *clientip;
FILE *fin;
FILE *fout;
//creating queue if debug!=1
if(runTimeArgs->debug!=1)
requeue= newReqQueue(-1);
else
requeue=newReqQueue(1);

schedQueue=newReqQueue(1);
pthread_key_create(&tName, NULL);
time_t t;
t = time(NULL);
char requestString[1024];
int sockfd = *((int*) sockid);
listen(sockfd, 5);

if(runTimeArgs->debug==1)
	nThreads=1;
	else if(runTimeArgs->threadCount>0)
	nThreads=runTimeArgs->threadCount;
	else 
	nThreads=4;

	createSchedulerAndSlaves(nThreads);

while(1){
clientLength = sizeof(client_addr);
cSockfd = accept(sockfd, (struct sockaddr *) &client_addr, &clientLength);


if(cSockfd < 0){
exit(0);
}
struct requestData *req=malloc(1* sizeof(*req));
req->next=NULL;
req->socketID=cSockfd;
clientip=inet_ntoa(client_addr.sin_addr);
req->clientIP=strdup(clientip);

read(cSockfd, requestString, sizeof(requestString));	// read request from socket
//printf("\n%s\n",requestString);
process_request(req,requestString);
req->queuedTime=strdup(asctime(gmtime(&t)));//gmtime(&t);//storing request queuing time in GMT
addRequestToQueue(requeue, req);

}
}
コード例 #3
0
PlatformNATTraversalWorker::~PlatformNATTraversalWorker() {
	stopRequested = true;
	addRequestToQueue(boost::shared_ptr<PlatformNATTraversalRequest>());
	thread->join();
	delete thread;
#ifdef HAVE_LIBNATPMP
	delete natPMPInterface;
#endif
#ifdef HAVE_LIBMINIUPNPC
	delete miniUPnPInterface;
#endif
	delete nullNATTraversalInterface;
}
コード例 #4
0
ファイル: myhttpd.c プロジェクト: devarshi150790/Project-OS1
void *scheduleRequest(void *arg){

	delayScheduling();
	time_t tim;
	tim=time(NULL);
	struct requestData *iterator;
	struct requestData *req = NULL;
	int *id = (int *)arg;

	pthread_setspecific(tName,(void *)id);

	int minsize;

	while (1) {

		pthread_mutex_lock(&requeue->lock);

		while(requeue->head == NULL){
					fflush(stdout);
					pthread_cond_wait(&requeue -> not_empty,&requeue->lock);
					fflush(stdout);
		}

		pthread_mutex_lock(&schedQueue->lock);

		while (schedQueue->queueSize == schedQueue->capacity) {
			fflush(stdout);
			pthread_cond_wait(&schedQueue->not_full, &schedQueue->lock);
			fflush(stdout);
		}

		pthread_mutex_unlock(&schedQueue->lock);

		iterator = requeue->head;
		minsize = -1;
		req = iterator;

		if (runTimeArgs->schedAlg != NULL && strcmp(runTimeArgs->schedAlg, "sjf") == 0) {
			

			while (iterator != NULL) {

				if (minsize == -1) {
					minsize = iterator->fileSize;
				}
				if (minsize > iterator->fileSize) {
					minsize = iterator->fileSize;
					req = iterator;
				}
				iterator = iterator->next;

			}
		}

		pthread_mutex_unlock(&requeue->lock);

		if (req != NULL) {
			deleteReqFromQueue(requeue, req);
			req->scheduledTime = strdup(asctime(gmtime(&tim)));//strdup(get_current_time_gmt());
			addRequestToQueue(schedQueue, req);
		}

		fflush(stdout);
	}

}
コード例 #5
0
ファイル: caching.c プロジェクト: OSGeo/zoo-project
/**
 * Try to load file from cache or download a remote file if not in cache
 *
 * @param m the maps containing the settings of the main.cfg file
 * @param content the map to update
 * @param hInternet the HINTERNET pointer
 * @param url the url to fetch
 * @return 0
 */
int loadRemoteFile(maps** m,map** content,HINTERNET* hInternet,char *url){
  char* fcontent = NULL;
  char* cached=isInCache(*m,url);
  char *mimeType=NULL;
  int fsize=0;

  map* t=getMap(*content,"xlink:href");
  if(t==NULL){
    t=getMap((*content),"href");
    addToMap(*content,"xlink:href",url);
  }

  if(cached!=NULL){

    struct stat f_status;
    int s=stat(cached, &f_status);
    if(s==0){
      fcontent=(char*)malloc(sizeof(char)*(f_status.st_size+1));
      FILE* f=fopen(cached,"rb");
      fread(fcontent,f_status.st_size,1,f);
      fsize=f_status.st_size;
      fcontent[fsize]=0;
      fclose(f);
      addToMap(*content,"cache_file",cached);
    }
    cached[strlen(cached)-1]='m';
    s=stat(cached, &f_status);
    if(s==0){
      mimeType=(char*)malloc(sizeof(char)*(f_status.st_size+1));
      FILE* f=fopen(cached,"rb");
      fread(mimeType,f_status.st_size,1,f);
      mimeType[f_status.st_size]=0;
      fclose(f);
    }

  }else{    
    addRequestToQueue(m,hInternet,url,true);
    return 0;
  }
  if(fsize==0){
    return errorException(*m, _("Unable to download the file."), "InternalError",NULL);
  }
  if(mimeType!=NULL){
    addToMap(*content,"fmimeType",mimeType);
  }

  map* tmpMap=getMapOrFill(content,"value","");
    
  free(tmpMap->value);
  tmpMap->value=(char*)malloc((fsize+1)*sizeof(char));
  if(tmpMap->value==NULL || fcontent == NULL)
    return errorException(*m, _("Unable to allocate memory"), "InternalError",NULL);
  memcpy(tmpMap->value,fcontent,(fsize+1)*sizeof(char));

  char ltmp1[256];
  sprintf(ltmp1,"%d",fsize);
  addToMap(*content,"size",ltmp1);
  if(cached==NULL){
    addToCache(*m,url,fcontent,mimeType,fsize, NULL, 0);
  }
  else{
    addToMap(*content,"isCached","true");
    map* tmp=getMapFromMaps(*m,"main","cacheDir");
    if(tmp!=NULL){
      map *c=getMap((*content),"xlink:href");
      char* md5str=getMd5(c->value);
      char* fname=(char*)malloc(sizeof(char)*(strlen(tmp->value)+strlen(md5str)+6));
      sprintf(fname,"%s/%s.zca",tmp->value,md5str);
      addToMap(*content,"cache_file",fname);
      free(fname);
    }
  }
  free(fcontent);
  free(mimeType);
  free(cached);
  return 0;
}