コード例 #1
0
ファイル: hamt.c プロジェクト: 4n3w/dump
void *hamt_delete(struct hamt_root *root, uint128_t *hash)
{
	if (unlikely(ston(root->slot) == NULL)) {
		return NULL;
	}

	struct hamt_state s;
        s.level = 0;
        s.ptr[0] = &root->slot;

	void *found_item = __hamt_search(root, hash, &s);
	if (unlikely(found_item == NULL)) {
		return NULL;
	}
	if (unlikely(s.level == 0)) {
		root->slot = (struct hamt_slot){0};
		goto done;
	}
	struct hamt_slot *found_slot = s.ptr[s.level];
	s.level--;

	struct hamt_node *node = ston(*s.ptr[s.level]);

	int slice = slice_get(*hash, s.level);
	if (set_count(node->mask) != 2) {
		*s.ptr[s.level] = ntos(__hamt_del_node(root, node, slice));
		goto done;
	} else { // set_count == 2
		struct hamt_slot other_slot = \
			__hamt_get_other_slot(node, found_slot);
		if(!is_leaf(&other_slot)) {
			uint64_t other_slice = set_first(set_del(node->mask, slice));
			__hamt_free_node(root, node);
			*s.ptr[s.level] = ntos(__hamt_new_node1(root, other_slice, other_slot));
			goto done;
		} else {
			while (1) {
				__hamt_free_node(root, node);
				if (unlikely(s.level == 0)) {
					root->slot = other_slot;
					goto done;
				}

				s.level--;
				node = ston(*s.ptr[s.level]);
				if (set_count(node->mask) != 1) {
					break;
				}
			}
			slice = slice_get(*hash, s.level);
			int slot = set_slot_number(node->mask, slice);
			node->slots[slot] = other_slot;
			goto done;
		}
	}
done:
	return found_item;
}
コード例 #2
0
ファイル: hamt.c プロジェクト: 4n3w/dump
static struct hamt_node *__hamt_add_slot(struct hamt_root *root,
					 struct hamt_slot *slot_ptr,
					 void *item, uint128_t *item_hash,
					 int level)
{
	uint64_t slice = slice_get(*item_hash, level);

	struct hamt_node *old_node = ston(*slot_ptr);
	int old_size = set_count(old_node->mask);
	int new_size = old_size + 1;
	struct hamt_node *node = __hamt_new_node(root,
						 set_add(old_node->mask, slice),
						 new_size);
	*slot_ptr = ntos(node);

	int slot = set_slot_number(node->mask, slice);

	memcpy(&node->slots[0], &old_node->slots[0],
	       sizeof(struct hamt_slot)*slot);
	memcpy(&node->slots[slot+1], &old_node->slots[slot],
	       sizeof(struct hamt_slot)*(old_size-slot));
	node->slots[slot] = item_to_slot(item);

	__hamt_free_node(root, old_node);
	return node;
}
コード例 #3
0
ファイル: FAT.cpp プロジェクト: anieshchawla/FAT-filesystem
int FAT::retrieve()
{
  message("FAT retrieve\n");

  // How many entries fit into a disk block?

  int entries_per_block = disk.block_size() / sizeof(int);

  // Get the FAT from Disk

  for (int block_num = 0; block_num < fat_num_blocks(); ++block_num)
  {
    char buf[MAX_BLOCK_SIZE];

    if (disk.read(block_num, buf) == DISK_ERROR)
      return DISK_ERROR;
    
    int index = entries_per_block * block_num;
    int entries;
    
    if (index + entries_per_block > disk.num_blocks())
      entries = disk.num_blocks() - index;
    else
      entries = entries_per_block;

    for (int pos = 0; pos < entries; ++pos)
      entry[index + pos] = ston(buf + sizeof(int)*pos);
  }

  // If the first entry is not FAT_END, the FAT on disk is invalid and we assume the disk was formatted.
  if (entry[0] != FAT_END)
    init();

  return DISK_OK;
}
コード例 #4
0
ファイル: hamt.c プロジェクト: 4n3w/dump
void *hamt_insert(struct hamt_root *root, void *item)
{
	uint128_t *item_hash = root->hash(root->hash_ud, item);
	assert(((unsigned long)item & ITEM_MASK) == 0);
	assert(item);

	if (unlikely(ston(root->slot) == NULL)) {
		root->slot = item_to_slot(item);
		return item;
	}

	struct hamt_state s;
        s.level = 0;
        s.ptr[0] = &root->slot;
        void *found_item = __hamt_search(root, item_hash, &s);

        if (unlikely(found_item != NULL)) {
                return found_item;
        }

        if (!is_leaf(s.ptr[s.level])) {
                __hamt_add_slot(root, s.ptr[s.level], item, item_hash, s.level);
        } else {
                void *leaf = to_leaf(s.ptr[s.level]);
                uint128_t *leaf_hash = root->hash(root->hash_ud, leaf);

                __hamt_insert_leaf(root, &s, item_hash, item, leaf_hash, leaf);
        }
	return item;
}
コード例 #5
0
ファイル: ohamt.c プロジェクト: pombredanne/ydb
static void __ohamt_delete(struct ohamt_root *root, uint128_t hash,
			   struct ohamt_state *s)
{
	if (unlikely(s->level == 0)) {
		root->slot = (struct ohamt_slot){0};
		goto done;
	}
	struct ohamt_slot *found_slot = s->ptr[s->level];
	s->level--;

	struct ohamt_node *node = ston(*s->ptr[s->level]);

	int slice = slice_get(hash, s->level);
	if (set_count(node->mask) != 2) {
		*s->ptr[s->level] = ntos(__ohamt_del_node(root, node, slice));
		goto done;
	} else { // set_count == 2
		struct ohamt_slot other_slot = \
			__ohamt_get_other_slot(node, found_slot);
		if(!is_leaf(&other_slot)) {
			uint64_t other_slice = set_first(set_del(node->mask, slice));
			__ohamt_free_node(root, node);
			*s->ptr[s->level] = ntos(__ohamt_new_node1(root, other_slice, other_slot));
			goto done;
		} else {
			while (1) {
				__ohamt_free_node(root, node);
				if (unlikely(s->level == 0)) {
					root->slot = other_slot;
					goto done;
				}

				s->level--;
				node = ston(*s->ptr[s->level]);
				if (set_count(node->mask) != 1) {
					break;
				}
			}
			slice = slice_get(hash, s->level);
			int slot = set_slot_number(node->mask, slice);
			node->slots[slot] = other_slot;
			goto done;
		}
	}
done:
	return;
}
コード例 #6
0
ファイル: ohamt.c プロジェクト: pombredanne/ydb
void ohamt_erase(struct ohamt_root *root)
{
	if (unlikely(ston(root->slot) == NULL)) {
		return;
	}

	__ohamt_erase(root, &root->slot);
}
コード例 #7
0
ファイル: hamt.c プロジェクト: 4n3w/dump
void *hamt_first(struct hamt_root *root, struct hamt_state *s)
{
	if (unlikely(ston(root->slot) == NULL)) {
		return NULL;
	}

	s->level = 0;
	s->ptr[0] = &root->slot;
	return __hamt_down(s);
}
コード例 #8
0
ファイル: ohamt.c プロジェクト: pombredanne/ydb
uint64_t ohamt_first(struct ohamt_root *root, struct ohamt_state *s)
{
	if (unlikely(ston(root->slot) == NULL)) {
		return OHAMT_NOT_FOUND;
	}

	s->level = 0;
	s->ptr[0] = &root->slot;
	return __ohamt_down(s);
}
コード例 #9
0
ファイル: ohamt.c プロジェクト: pombredanne/ydb
static inline void __ohamt_erase(struct ohamt_root *root,
                                  struct ohamt_slot *slot)
{
	if (!is_leaf(slot)) {
		struct ohamt_node *node = ston(*slot);
		int i;
		for (i=0; i < set_count(node->mask); i++) {
			__ohamt_erase(root, &node->slots[i]);
		}
		__ohamt_free_node(root, node);
		slot->off = 0;
	}
}
コード例 #10
0
ファイル: execpt.cpp プロジェクト: bduck/livecode
Exec_stat MCExecPoint::getreal8(real8 &d, uint2 l, uint2 p, Exec_errors e)
{
	if (format == VF_STRING)
		if (ston() != ES_NORMAL)
		{
			MCeerror->add
			(EE_VARIABLE_NAN, l, p, svalue);
			MCeerror->add
			(e, l, p, svalue);
			return ES_ERROR;
		}
	d = nvalue;
	return ES_NORMAL;
}
コード例 #11
0
ファイル: ohamt.c プロジェクト: pombredanne/ydb
void ohamt_delete_all(struct ohamt_root *root,
		      void (*fun)(void *ud, uint64_t item), void *ud)
{
	struct ohamt_state s;
	while (ston(root->slot) != NULL) {
		s.level = 0;
		s.ptr[0] = &root->slot;
		uint64_t found_item = __ohamt_down(&s);
		uint128_t hash = root->hash(root->hash_ud, found_item);
		__ohamt_delete(root, hash, &s);

		fun(ud, found_item);
	}
}
コード例 #12
0
ファイル: hamt.c プロジェクト: 4n3w/dump
static void *__hamt_down(struct hamt_state *s)
{
	if (!is_leaf(s->ptr[s->level])) {
                struct hamt_node *node = ston(*s->ptr[s->level]);
		int slice = set_first(node->mask);
		s->hash = slice_set(s->hash, slice, s->level);

		int slot = set_slot_number(node->mask, slice);
		s->ptr[s->level + 1] = &node->slots[slot];
		s->level += 1;
		return __hamt_down(s);
	} else {
                return to_leaf(s->ptr[s->level]);
	}
}
コード例 #13
0
ファイル: execpt.cpp プロジェクト: bduck/livecode
Exec_stat MCExecPoint::getuint4(uint4 &d, uint2 l, uint2 p, Exec_errors e)
{
	if (format == VF_STRING)
		if (ston() != ES_NORMAL)
		{
			MCeerror->add
			(EE_VARIABLE_NAN, l, p, svalue);
			MCeerror->add
			(e, l, p, svalue);
			return ES_ERROR;
		}
	if (nvalue < 0.0)
		d = (uint4)(nvalue - 0.5);
	else
		d = (uint4)(nvalue + 0.5);
	return ES_NORMAL;
}
コード例 #14
0
ファイル: ohamt.c プロジェクト: pombredanne/ydb
uint64_t ohamt_delete(struct ohamt_root *root, uint128_t hash)
{
	if (unlikely(ston(root->slot) == NULL)) {
		return OHAMT_NOT_FOUND;
	}

	struct ohamt_state s;
        s.level = 0;
        s.ptr[0] = &root->slot;

	uint64_t found_item = __ohamt_search(root, hash, &s);
	if (unlikely(found_item == OHAMT_NOT_FOUND)) {
		return OHAMT_NOT_FOUND;
	}

	__ohamt_delete(root, hash, &s);
	return found_item;
}
コード例 #15
0
ファイル: forza_server.c プロジェクト: giannix90/Forza-4-game
int main(int argc,char * argv[])
{	
	if(argv[1]==NULL || argv[2]==NULL)
		{
			perror("Errore : Inserisci un comando del tipo ./forza_server <host> <porta> \n");
			//sleep(2);
			_exit(1);
		}

	char yes;
	int i=0;
	int new_client_socket=0;
	/* timer per select*/
	struct timeval tv;
	tv.tv_sec=60;
	tv.tv_usec=0;	
		
	
	char c;
	sk_TCP=socket(AF_INET,SOCK_STREAM,0);
	memset(&my_par,0,sizeof(my_par));
	my_par.sin_family=AF_INET;
	my_par.sin_port=htons(ston(argv[2]));
	inet_pton(AF_INET,argv[1],&my_par.sin_addr.s_addr);
	
if(setsockopt(sk_TCP,SOL_SOCKET,SO_REUSEADDR,&yes,sizeof(int))==-1)
	{
	printf("Setsock err\n");
	_exit(-1);	
	}	
	int ret=bind(sk_TCP,(struct sockaddr *)&my_par,sizeof(my_par));
	if(ret<0)
	{
		printf("Errore bind()");
		_exit(-1);
	}
	
	ret=listen(sk_TCP,10);
	if(ret<0)
	{
		printf("Errore listen");
		_exit(-1);
	}
	
	printf("Indirizzo: %s (Porta: %s)\n",argv[1],argv[2]);
		
	/*azzera le maschere per i descrittori usati nella select*/
	FD_ZERO(&master);
	FD_ZERO(&read_fds);
	/*aggiunge alla maschera i descrittori sk_udp*/
	FD_SET(sk_TCP,&master);
	
	fdmax=sk_TCP;	
	while(1)
	{
	
		/*reset del timer select()*/
		tv.tv_sec=60;
		tv.tv_usec=0;
		read_fds=master;

	
		if(select(fdmax+1,&read_fds,NULL,NULL,&tv)==-1)
		{
			printf("Select() error!");
			_exit(1);
		}
		
		for(i=0;i<=fdmax;i++)
		{
			if(FD_ISSET(i,&read_fds))
			{
			if(i==sk_TCP)
			{
				/*socket listener di ascolto, richiesta di connessione da parte di un client*/
				socklen_t size=sizeof(struct sockaddr_in);
				struct sockaddr_in * ind= crea_player();
				new_client_socket=accept(sk_TCP,(struct sockaddr* )ind,&size);
				configura_player(testa,new_client_socket,NULL);
				FD_SET(new_client_socket,&master);	
				printf("Connessione stabilita con il client\n");
				if(fdmax<new_client_socket)fdmax=new_client_socket;

				
			}
			
			else
			{
				
				/*dati in arrivo da un client, bisogna veder quale*/
				int ret=recv(i,(void *)buf_inTCP,MAXTCP,0);  //ricevo i dati	
				if(ret>0)
				{
				//printf("Type :%s\n",buf_inTCP);
				controllo_tipo(i);				

				
				//FD_CLR(i,&master); //tolgo il descrittore da quelli da controllare
				}

				else
				{
					struct players * p;
					cerca_per_sk(i,(void *) &p);
					printf("%s si e' disconnesso dal server\n",p->name);
					FD_CLR(i,&master);
					close(i);
					elimina_players(i);
					//stampa_giocatori(testa);
					num_players--;
					
					
				}
				
			}
		}
	}
}	
		
	scanf("Inserisci invio,%c\n",&c);
	return 0;
}
コード例 #16
0
ファイル: hamt.c プロジェクト: 4n3w/dump
static inline struct hamt_slot item_to_slot(void *item)
{
        return (struct hamt_slot){(uint64_t)item | LEAF_MASK};
}

static inline struct hamt_node *ston(struct hamt_slot slot)
{
	return (struct hamt_node *)(uint64_t)slot.off;
}

static inline struct hamt_slot ntos(struct hamt_node *node)
{
	return (struct hamt_slot){(uint64_t)node};
}

/**************************************************************************/

static inline void *__hamt_search(struct hamt_root *root,
                                  uint128_t *hash,
                                  struct hamt_state *s)
{
        if (!is_leaf(s->ptr[s->level])) {
                struct hamt_node *node = ston(*s->ptr[s->level]);

		int slice = slice_get(*hash, s->level);
		if (set_contains(node->mask, slice)) {
                        s->hash = slice_set(s->hash, slice, s->level);
			int slot = set_slot_number(node->mask, slice);
                        s->ptr[s->level + 1] = &node->slots[slot];
                        s->level += 1;
                        return __hamt_search(root, hash, s);
                }
                return NULL;
        } else {
                void *item = to_leaf(s->ptr[s->level]);
                if (*root->hash(root->hash_ud, item) == *hash) {
                        return item;
                } else {
                        return NULL;
                }
        }
}

void *hamt_search(struct hamt_root *root, uint128_t *hash)
{
	if (unlikely(ston(root->slot) == NULL)) {
		return NULL;
	}

        struct hamt_state s;
        s.level = 0;
        s.ptr[0] = &root->slot;

	return __hamt_search(root, hash, &s);
}

/**************************************************************************/

static struct hamt_node *__hamt_new_node(struct hamt_root *root, uint64_t mask,
                                         int len)
{
	int size = sizeof(struct hamt_node) + len * sizeof(struct hamt_slot);
	struct hamt_node *node = \
		(struct hamt_node *)root->mem_alloc(size);
	assert(((unsigned long)node & ITEM_MASK) == 0);
	node->mask = mask;
	return node;
}
コード例 #17
0
int RPC::dispatch(Disk& disk)
{
  char buf[NDISK_BLOCK_SIZE];
  char packet[NDISK_BLOCK_SIZE + 8];

  size_t len = NDISK_BLOCK_SIZE + 8;
  char *msg = packet;

  if (disk.block_size() != NDISK_BLOCK_SIZE)
    return DISK_ERROR;

  // Read the packet (with 8-byte header)
  do
  {
    ssize_t nread = recv(sock, msg, len, 0);

    if (nread <= 0)
      return DISK_ERROR;

    len -= nread;
    msg += nread;
  }
  while (len > 0);

  // Get the command from the packet's first four bytes
  char command[5];
  memcpy(command, packet, 4);
  command[4] = '\0';

  // Get the block number parameter from the packet
  int block_num = ston(packet + 4);

  if (!strcmp(command, "NUMB"))
  {
    // Write num blocks into packet data
    ntos(packet + 8, disk.num_blocks());
  }
  else if (!strcmp(command, "FRMT"))
  {
    disk.format(block_num);
  }
  else if (!strcmp(command, "READ"))
  {
    disk.read(block_num, buf);
    memcpy(packet + 8, buf, NDISK_BLOCK_SIZE);
  }
  else if (!strcmp(command, "WRTE"))
  {
    memcpy(buf, packet + 8, NDISK_BLOCK_SIZE);
    disk.write(block_num, buf);
  }
  else
  {
    message1("Unknown RPC command %s\n", command);
  }

  message2("RPC command %s(%d)\n", command, block_num);

  len = NDISK_BLOCK_SIZE + 8;
  msg = packet;

  // Write the packet (with 8-byte header)
  do
  {
    ssize_t nwritten = send(sock, msg, len, 0);

    if (nwritten < 0)
      return DISK_ERROR;

    len -= nwritten;
    msg += nwritten;
  }
  while (len > 0);

  return DISK_OK;
}
コード例 #18
0
int main(int argc, char ** argv){
	int  i, maxi, maxfd, listenfd, connfd, sockfd,val,nwritten;
	int  nready, client[NUMBEROFSTATIONS];
	ssize_t  n;
	fd_set   rset, allrset, wset,allwset;
	socklen_t    clilen;
	struct sockaddr_in    cliaddr, servaddr;
	int frame_number;
	int source_station_number;
	int destination_sockfd; //used to assign destination station socket number, 
	char *message1; //used to store first message
	char *message2; //used to store second message
	char source[INET_ADDRSTRLEN]; //used to the  third parameter of function inet_ntop
	char *sourceIP; //used to stored IP address of SP
	
	/* dest is an array that will store the destination station numbers
	and their corresponding socket descriptors. This will later be used to 
	send frame to destination station after receiving both messages of frame */	
	char *destinationIP; 
	char *destination_addr;
	int stored_destination_number;
	struct destination dest[NUMBEROFSTATIONS];
	/* initilize each station's sockfd to -1 */
	for (i = 0; i < NUMBEROFSTATIONS; i++){
		(dest + i)->destination_sockfd = -1;
	}
	
	struct frame * receiving_framePtr;
	struct cbp_storage  cbs;
	char col_mes[COLLISIONMESSAGE] = "Collision";
	char *collision_message = col_mes;

	listenfd = Socket(AF_INET, SOCK_STREAM, 0);
	bzero(&servaddr, sizeof(servaddr));
	servaddr.sin_family      = AF_INET;
	servaddr.sin_addr.s_addr = htonl(INADDR_ANY);
	servaddr.sin_port        = htons(SERV_PORT);

	Bind(listenfd, (SA *) &servaddr, sizeof(servaddr));

	Listen(listenfd, LISTENQ);

	maxfd = listenfd;                       /* initialize */
	maxi = -1;                                      /* index into client[] array */
	
	/* Set to non-blocking mode using Fcntl for non-blocking IO*/
	
	/* Set socket descriptor that write to CBP output */
	val = Fcntl(fileno(stdout), F_GETFL, 0);
	Fcntl(fileno(stdout), F_SETFL, val | O_NONBLOCK);
	
	val = Fcntl(fileno(stdin), F_GETFL, 0);
	Fcntl(fileno(stdin), F_SETFL, val | O_NONBLOCK);
	for (i = 0; i < NUMBEROFSTATIONS; i++)
			client[i] = -1;                 /* -1 indicates available entry */
	FD_ZERO(&allrset);
	FD_ZERO(&allwset);
	FD_SET(listenfd, &allrset);
	
	maxfd = listenfd;
	
	int ctClient = 0;
	


    for ( ;; ) {
			
	rset = allrset; 
	//wset = allwset;/* structure assignment */
	nready = Select(maxfd+1, &rset, NULL, NULL, NULL);
	if (ctClient == NUMBEROFSTATIONS){			
		if (FD_ISSET(listenfd, &rset)) {        /* new client connection */
			clilen = sizeof(cliaddr);
			connfd = Accept(listenfd, (SA *) &cliaddr, &clilen);
			
			printf("New connection, sockfd: %d\n",connfd);	
			/* Save the just-connected station, e.i. its socket descriptor and its station number
			This information will later be used to send frame to destination station after
			receiving both message of frame */
			destinationIP = Inet_ntop(AF_INET, &cliaddr.sin_addr,source,INET_ADDRSTRLEN);
			stored_destination_number = ston(destinationIP);
			for (i = 0; i < NUMBEROFSTATIONS; i++){
				if((dest+i)->destination_sockfd < 0){
					(dest+i)->destination_sockfd = connfd;
					(dest+i)->destination_station_number = stored_destination_number;
					break;
				}
			}			
			/* Set socket descriptor to and from SP using Fcntl for non-blocking IO*/	
			val = Fcntl(connfd, F_GETFL, 0);
			Fcntl(connfd, F_SETFL, val | O_NONBLOCK);

			for (i = 0; i < NUMBEROFSTATIONS; i++)
				if (client[i] < 0) {
					client[i] = connfd; 
					ctClient++; 
					break;
				}
			FD_SET(connfd, &allrset);
			FD_SET(connfd, &allwset);

			if (connfd > maxfd)	
					maxfd = connfd;                
			if (i > maxi)
					maxi = i;                           

			if (--nready <= 0)
					continue;                          
	
		}       
		else //Clients full
		{
			break;
		}
	}
	}
	
	/*All Sps are now connect to the CBP, ready for sending frames*/	
	
	/*buffer_acquired is set to:   0 when first part of frame received																       1 when the second part of the frame sent, making the buffer ready for new frame 
					 or when a collision happens, discards the remaining part of the frame, allows stations to acquire the CBP storage
	*/
	char response;	
	printf("All stations are connected, ready to exchage data (Y/N):  \n");
        scanf("%*c %c",&response);
        if( (response == 'y') || (response == 'Y') ){	
	int buffer_acquired = 1;
	for( ; ; ){
	
		
		nready = Select(maxfd+1, &rset, &wset, NULL, NULL);

        for (i = 0; i <= maxi; i++) {   /* check all clients for data */
			sockfd = client[i];
			FD_SET(sockfd, &rset);
			sourceIP = Inet_ntop(AF_INET, &cliaddr.sin_addr,source,INET_ADDRSTRLEN);
			source_station_number = ston(sourceIP);
			
			if(buffer_acquired){	
				if(FD_ISSET(sockfd, &rset)){
					buffer_acquired = 0;
					if(n = Read(sockfd, receiving_framePtr,MAXLINE) == 0){
							Close(sockfd);
							FD_CLR(sockfd,&allrset);
							client[i] = -1;
					}
					else{
						/* Get information from struct frame type variable pointed by receiving_framePtr pointer
						that is received from SP */
						frame_number = receiving_framePtr->frame_number;						
						message1 = receiving_framePtr->message1;
						destination_addr = receiving_framePtr->destination_addr;
						int destination_station_number = ston(destination_addr);
						
						//inspect the message1					
						cbs.source_station_sd = sockfd;
						cbs.source_station_number = source_station_number;
						cbs.destination_station_number = destination_station_number;
						cbs.frame_number = frame_number;			
						strcpy(cbs.message1,message1);

						/*Turn on the bit to write to stdout*/
						FD_SET(fileno(stdout), &wset);
						if(FD_ISSET(fileno(stdout), &wset))
							fprintf(stdout,"Receive %s of frame %d from Station %d,to Station %d\n",
											message1,frame_number,source_station_number,destination_station_number);														
					}
					if (--nready <= 0)
						break;				/* no more readable descriptors */
				}
			}
			else{ 
				/* Buffer already store first message of a frame of a station
				Check if the receiving message is the second frame of that frame or
				the first message of a frame from another station */
				if (FD_ISSET(sockfd, &rset)){
					if(n = Read(sockfd, receiving_framePtr,MAXLINE) == 0){
						Close(sockfd);
						FD_CLR(sockfd,&allrset);
						client[i] = -1;
					}				
					else{/* Inspect the message if it is the second message 
							or the first message from another frame of another station*/
	
						/* Get information from struct frame type variable pointed by receiving_framePtr pointer
						that is received from SP */
						frame_number = receiving_framePtr->frame_number;			//get frame number				
						message2 = receiving_framePtr->message2;						//get the second message
						destination_addr = receiving_framePtr->destination_addr;	//get the destination address (string)
						int destination_station_number = ston(destination_addr);	//convert to number using ston function

						//Inspect the message
						//Check if the current source station number is the one whose first message has already been saved to CBP storage
						//If yes, save the second message
						if(cbs.source_station_number == source_station_number && 
									cbs.frame_number == frame_number){
							if(strcmp(message2,"part 2"==0)){
								strcpy(cbs.message2,message2);
							/*Turn on the bit to write to stdout*/
							FD_SET(fileno(stdout), &wset);
							if(FD_ISSET(fileno(stdout), &wset))
								fprintf(stdout,"Receive %s of frame %d from Station %d,to Station %d\n",
												message1,frame_number,source_station_number,destination_station_number);
								/* Turn on the bit in the wset to write to desination station the first message 
									Get the destination socket number from the dest array
								*/
								
								for( i = 0; i<NUMBEROFSTATIONS; i++){
									if((dest+i)->destination_station_number == cbs.destination_station_number)
										break;
								}
								destination_sockfd = (dest+i)->destination_sockfd;
								FD_SET(destination_sockfd, &wset);
							}
						}
						else{ /* Receiving frame from another station, inform both station a collision*/
						
							 /* Sending collision message to station that accquired the bus, discards the remaing parts of frame */						 
							buffer_acquired = 1;
							FD_SET(cbs.source_station_sd, &wset);		
							if(FD_ISSET(cbs.source_station_sd, &wset))
								Writen(cbs.source_station_sd, collision_message, strlen(COLLISIONMESSAGE));
								
							/*Sending collision message to another station*/
							if(FD_ISSET(sockfd, &wset))
								Writen(sockfd, collision_message, strlen(COLLISIONMESSAGE));
						}
					}
					if (--nready <= 0)
						break;				/* no more readable descriptors */
				}	
			}
			/* Sending the first message of the frame to destinaition SP*/

				
			} 
					

        }

    }




}