Beispiel #1
0
/* q_get returns a pointer to the buffer where data is read or NULL if
 * buffer is empty.
 */
static Byte *q_get(int sockfd, QTYPE *queue) {
	int emptySpace = EmptySpace(*queue);

	if (emptySpace < RXQSIZE) {
		/*
		Retrieve data from buffer
		If the number of characters in the receive buffer is below certain
		level, then send XON.
		Increment front index and check for wraparound.
		*/
		if ( ( emptySpace >= maxLowerLimit ) && ( x == 0 ) ) {
			char state[1];

			printf("Buffer < maximum lowerlimit. Mengirim XON.\n");
			sprintf(state, "%c",(char) XON);
			if (sendto(sockfd, state, 1, 0, (struct sockaddr *)&targetAddr, addrLen)==-1) {
				perror("sendto");
			}
			x = 1;

			sleep(5);

			return NULL;

		} else {

			consumed[0] = Del(queue);
			
			while ( !(consumed[0] >= 32 || consumed[0] == 13 || consumed[0] == 10) && EmptySpace(*queue) > 0 ) {
				consumed[0] = Del(queue);
			}

			return consumed;

		}
	} else {
		/* Nothing in the queue */
		return NULL;
	}

}
Beispiel #2
0
void DrawMaze (int height, int width, int **Maze, int ascii)
{
  int i, j;
  printf("newpath 100 200 moveto\n");
  printf("%d 0 rlineto 0 %d rlineto \n", width*TILESIZE, height*TILESIZE);
  printf("-%d 0 rlineto 0 -%d rlineto \n", width*TILESIZE, height*TILESIZE);
  printf("stroke closepath\n\nnewpath\n 100 %d moveto\n", 200+height*TILESIZE);
  for(i=0;i<width;i++){
    for(j=0; j<height;j++){
      if(!ascii){printf("%% ");}
      printf("%d ",Maze[i][j]);
    }
    printf("\n");
  }
  for(i=0;i<width;i++){
    for(j=0; j<height;j++){
      if(!ascii){
	switch(Maze[i][j]){
	case RIGHTWALL:
	  Rightwall(i+j);
	  break;
	case LEFTWALL:
	  Leftwall(i+j);
	  break;
	case UPWALL:
	  Upwall(i+j);
	  break;
	case DOWNWALL:
	  Downwall(i+j);
	  break;
	default:
	  EmptySpace(i+j);
	  break;
	}
      }
    }
    printf("\t%%New level\n\t %d -%d rmoveto\n",-width*TILESIZE,TILESIZE);
  }
  printf("closepath stroke showpage");
  return;
}
Beispiel #3
0
static Byte *rcvchar(int sockfd, QTYPE* queue) {
	/*
	Read a character from socket and put it to the receive buffer.
	If the number of characters in the receive buffer is above certain
	level, then send XOFF and set a flag.
	Return a buffer value.
	*/
	int emptySpace = EmptySpace(*queue);

	if (emptySpace <= minUpperLimit) {
		char state[1];

		printf("Buffer > minimum upperlimit. Mengirim XOFF.\n");
		sprintf(state, "%c",(char) XOFF);
		if (sendto(sockfd, state, 1, 0, (struct sockaddr *)&targetAddr, addrLen) == -1) {
			perror("sendto");
		}

		x = 0;

		sleep(5);
		
		return NULL;

	} else {

		recvLen = recvfrom(sockfd, buf, 1, 0, (struct sockaddr *)&targetAddr, &addrLen);

		if ( buf[0] != 26 ) {
			Add(queue, buf[0]);
		}	

		return buf;
	}

}