Example #1
0
void
GsCloseSocket(void)
{
#if !HELLOOS
	if(un_sock != -1)
		close(un_sock);
	un_sock = -1;
	unlink(GR_NAMED_SOCKET);
#else /*!HELLOS*/
	if(un_sock != -1)
		bucket_close(un_sock);
	un_sock = -1;
#endif /*!HELLOS*/
}
Example #2
0
/*
 * This is used to drop a client when it is detected that the connection to it
 * has been lost.
 */
void
GsDropClient(int fd)
{
	GR_CLIENT *client;

	if((client = GsFindClient(fd))) { /* If it exists */
#if !HELLOOS
		close(fd);	/* Close the socket */
#else
#if !NONETWORK
		bucket_close(fd);
#endif
#endif
		GsDestroyClientResources(client);
		if(client == root_client)
			root_client = client->next;
		/* Link the prev to the next */
		if(client->prev) client->prev->next = client->next;

		/* Link the next to the prev */
		if(client->next) client->next->prev = client->prev;

#if HAVE_SHAREDMEM_SUPPORT
		if ( client->shm_cmds != 0 ) {
			/* Free shared memory */
			shmctl(client->shm_cmds_shmid,IPC_RMID,0);
			shmdt(client->shm_cmds);
		}
#endif
GsPrintResources();
		free(client);	/* Free the structure */

		clipwp = NULL;	/* reset clip window*/
		--connectcount;
	} else EPRINTF("nano-X: trying to drop non-existent client %d.\n", fd);
}
Example #3
0
// this function will take the current array, and put it aside, creating a new array based on the 
// new mask supplied (we can only make the mask bigger, and cannot shrink it).
// We create a new array, and for each entry, we compare it against the old mask, and use 
// the data for that hash from the old list.
// NOTE: We may be starting off with an empty lists.  If this is the first time we've 
//       received some hashmasks.  To implement this easily, if we dont already have hashmasks, we 
//       may need to create one that has a dummy entry in it.
void buckets_split_mask(hash_t current_mask, hash_t new_mask) 
{
	bucket_t **newbuckets = NULL;
	bucket_t **oldbuckets = NULL;
	
	int i;
	int index;
	
	assert(new_mask > current_mask);
	
	logger(LOG_INFO, "Splitting Mask: Old Mask: %#llx, New Mask; %#llx", current_mask, new_mask);
	
	// grab a copy of the existing buckets as the 'oldbuckets';
	oldbuckets = _buckets;
	_buckets = NULL;
	
	// make an appropriate sized new buckets list;
	newbuckets = malloc(sizeof(bucket_t *) * (new_mask+1));
	assert(newbuckets);
	
	// go through every hash for this mask.
	for (i=0; i<=new_mask; i++) {

		// determine what the old index is.
		index = i & current_mask;
		
		// create the new bucket ONLY if we already have a bucket object for that index.
		if (oldbuckets == NULL || oldbuckets[index] == NULL) {
			newbuckets[i] = NULL;
		}
		else {
			// we have a bucket for this old index.  So we need to create a new one for this index.
			
			
			newbuckets[i] = bucket_new(i);

			assert(newbuckets[i]->data);
			assert(newbuckets[i]->data->next == NULL);
			assert(oldbuckets[index]->data);
			assert(oldbuckets[index]->data->ref > 0);
			newbuckets[i]->data->next = oldbuckets[index]->data;
			oldbuckets[index]->data->ref ++;

			assert(newbuckets[i]->hashmask == i);
			newbuckets[i]->level = oldbuckets[index]->level;
			
			newbuckets[i]->source_node = oldbuckets[index]->source_node;
			newbuckets[i]->backup_node = oldbuckets[index]->backup_node;
			newbuckets[i]->logging_node = oldbuckets[index]->logging_node;
			
			newbuckets[i]->primary_node = oldbuckets[index]->primary_node;
			newbuckets[i]->secondary_node = oldbuckets[index]->secondary_node;
			
			assert(data_in_transit() == 0);
		}
	}

	assert(_mask >= 0);
	assert(new_mask > _mask);
	_mask = new_mask;
	
	// clean up the old buckets list.
	if (oldbuckets) {
		for (i=0; i<=_mask; i++) {
			if (oldbuckets[i]) {
				assert(oldbuckets[i]->data);
				assert(oldbuckets[i]->data->ref > 1);
				oldbuckets[i]->data->ref --;
				assert(oldbuckets[i]->data->ref > 0);
				
				oldbuckets[i]->data = NULL;
				
				bucket_close(oldbuckets[i]);
			}
		}
	}	
	
	_buckets = newbuckets;
	assert(_buckets);
}
Example #4
0
int tst_bucket()
{
  int fd;
  char s[16];
  int rc;
  char *buffer;
  int j;
  fd_set fdset;
  int fdsize=0;

  rc=fd=bucket_open();
  if(rc<0) {
    display_puts("open error=");
    int2dec(-rc,s);
    display_puts(s);
    display_puts("\n");
    return 1;
  }

  rc=bucket_connect(fd, BKT_QNM_BUCKET, BKT_SRV_BUCKET);
  if(rc<0) {
    display_puts("connect error=");
    int2dec(-rc,s);
    display_puts(s);
    display_puts("\n");
    return 1;
  }


  buffer=malloc(4096);
  memcpy(buffer,"ABC",3);
  rc=bucket_send(fd, buffer, 3);
  if(rc<0) {
    display_puts("send error=");
    int2dec(-rc,s);
    display_puts(s);
    display_puts("\n");
    return 1;
  }
  memcpy(buffer,"DEF",3);
  rc=bucket_send(fd, buffer, 3);
  if(rc<0) {
    display_puts("send error=");
    int2dec(-rc,s);
    display_puts(s);
    display_puts("\n");
    return 1;
  }

//  rc=bucket_shutdown(fd);
//  if(rc<0) {
//    display_puts("shutdown error=");
//    int2dec(-rc,s);
//    display_puts(s);
//    display_puts("\n");
//    return 1;
//  }

  rc=bucket_shutdown(fd);

  j=0;
  while(j<5) {
    display_puts("receiving(client)...");
    fdsize=max(fdsize,fd);
    FD_ZERO(&fdset);
    FD_SET(fd,&fdset);
    rc=bucket_select(fdsize+1,&fdset, 0);
    if(rc<0) {
      display_puts("select error=");
      int2dec(-rc,s);
      display_puts(s);
      display_puts("\n");
      return 1;
    }
    display_puts("\n");

    rc=bucket_recv(fd, buffer, 6);
    if(rc<0) {
      display_puts("recv error=");
      int2dec(-rc,s);
      display_puts(s);
      display_puts("\n");
      return 1;
    }
    display_puts("received(client) bucket:");
    int2dec(rc,s);
    display_puts(s);
    display_puts("byte.(");
    buffer[rc]=0;
    display_puts(buffer);
    display_puts(")\n");

    if(rc==0)
      break;

syscall_wait(100);
    j++;
  }

  rc=bucket_close(fd);
  display_puts("done(client)\n");

  return 0;
}