int
tcp_connect(int sockfd, const char *rem_addr, unsigned short port)
{
  struct sockaddr_in addr;
  int addrlen;
  long ipno;

#ifdef WIN32
  sockfd = win32_file_table[sockfd].win32id;
#endif

  if ( convert_address(&ipno , rem_addr) < 0 )
  {
    return -1;
  }

  addrlen = sizeof(struct sockaddr_in);

  memset((char *) &addr, 0, sizeof(struct sockaddr_in));
  addr.sin_family      = AF_INET;
  addr.sin_addr.s_addr = ipno;
  addr.sin_port        = htons(port);

  if (connect(sockfd, (struct sockaddr *)&addr, addrlen) < 0)
  {
    debug(DEBUG_ERROR, "connect error");
    return -1;
  }
  
  debug(DEBUG_STATUS, "tcp: connection established on port %d", port);
  return 0;
}
Example #2
0
static void read_client_command(uev_t *w, void *arg, int UNUSED(events))
{
	int              active = 1;
	ctrl_t          *ctrl = (ctrl_t *)arg;
	ssize_t          len;
	uint16_t         port, op, block;
	struct sockaddr *addr = (struct sockaddr *)&ctrl->client_sa;
	socklen_t        addr_len = sizeof(ctrl->client_sa);

	/* Reset inactivity timer. */
	uev_timer_set(&ctrl->timeout_watcher, INACTIVITY_TIMER, 0);

	memset(ctrl->buf, 0, ctrl->bufsz);
	len = recvfrom(ctrl->sd, ctrl->buf, ctrl->bufsz, 0, addr, &addr_len);
	if (-1 == len) {
		if (errno != EINTR)
			ERR(errno, "Failed reading command/status from client");

		uev_exit(w->ctx);
		return;
	}

	convert_address(&ctrl->client_sa, ctrl->clientaddr, sizeof(ctrl->clientaddr));
	port   = ntohs(((struct sockaddr_in *)addr)->sin_port);
	op     = ntohs(ctrl->th->th_opcode);
	block  = ntohs(ctrl->th->th_block);

	switch (op) {
	case RRQ:
		len -= ctrl->th->th_stuff - ctrl->buf;
		if (parse_RRQ(ctrl, ctrl->th->th_stuff, len)) {
			ERR(errno, "Failed parsing TFTP RRQ");
			active = 0;
			break;
		}
		DBG("tftp RRQ %s from %s:%d", ctrl->file, ctrl->clientaddr, port);
		active = handle_RRQ(ctrl);
		free(ctrl->file);
		break;

	case ERROR:
		DBG("tftp ERROR: %hd", ntohs(ctrl->th->th_code));
		active = 0;
		break;

	case ACK:
		DBG("tftp ACK, block # %hu", block);
		active = handle_ACK(ctrl, block);
		break;

	default:
		DBG("tftp opcode: %hd", op);
		DBG("tftp block#: %hu", block);
		break;
	}

	if (!active)
		uev_exit(w->ctx);
}
int add_transaction(	tick_t now, int transaction_type, int slot_id,int *chan_id){
	transaction_t   *this_t = NULL;
	uint64_t    address = 0;
	addresses_t     this_a; 
	int		transaction_index;
	int		thread_id;
	thread_id = get_thread_id(global_biu,slot_id);

		address 			= get_physical_address(global_biu, slot_id);
		this_a.physical_address 	= address;
		// We need to setup an option in case address is already broken down!
		if (convert_address(dram_system.config.physical_address_mapping_policy, &dram_system.config,&(this_a)) == ADDRESS_MAPPING_FAILURE) {
		  /* ignore address mapping failure for now... */
	  }
//	  if(thread_id != -1){
	  if(thread_id != -1 ){
		int scramble_id = get_thread_set(thread_id);
		this_a.chan_id     = (this_a.chan_id + scramble_id) % dram_system.config.channel_count;
		this_a.rank_id     = (this_a.rank_id + scramble_id) % dram_system.config.rank_count;
		this_a.bank_id     = (this_a.bank_id + scramble_id) % dram_system.config.bank_count;
		this_a.row_id      = (this_a.row_id + scramble_id) % dram_system.config.row_count;
	  }

	*chan_id = this_a.chan_id;
	if(dram_system.dram_controller[this_a.chan_id].transaction_queue.transaction_count >= (dram_system.config.max_tq_size)){
	  return MEM_STATE_INVALID;
	} 
	transaction_index = dram_system.dram_controller[this_a.chan_id].transaction_queue.transaction_count;
	if (dram_system.dram_controller[this_a.chan_id].transaction_queue.transaction_count <= 0) {
	  dram_system.tq_info.last_transaction_retired_time = dram_system.current_dram_time;
	  //fprintf(stdout,"Reset retired time to %llu\n",dram_system.tq_info.last_transaction_retired_time);
	}
	this_a.thread_id = thread_id;
	this_t = &(dram_system.dram_controller[this_a.chan_id].transaction_queue.entry[transaction_index]);	/* in order queue. Grab next entry */
	
	this_t->status 			= MEM_STATE_VALID;
	this_t->arrival_time 		= now;
	this_t->completion_time 	= 0;
	this_t->transaction_type 	= transaction_type;
	this_t->transaction_id 	= dram_system.tq_info.transaction_id_ctr++;
	this_t->slot_id			= slot_id;
	this_t->critical_word_ready	= FALSE;
	this_t->critical_word_available	= FALSE;
	this_t->critical_word_ready_time= 0;
	this_t->issued_data = false;
	this_t->issued_command = false;
	this_t->issued_cas = false;
	this_t->issued_ras = false;
	this_t->tindex = transaction_index;


	// Update Address
	this_t->address.physical_address= address;
	this_t->address.chan_id= this_a.chan_id;
	this_t->address.bank_id= this_a.bank_id;
	this_t->address.rank_id= this_a.rank_id;
	this_t->address.row_id= this_a.row_id;
	  /* STATS FOR RANK & CHANNEL */
	  rank_distrib[ this_a.chan_id ][ this_a.rank_id ]++;
	  tot_reqs++;

	  /* */
		
	mem_gather_stat(GATHER_REQUEST_LOCALITY_STAT, (int)address);		/* send this address to the stat collection */

	if(get_transaction_debug()){
		print_addresses(&(this_a));
	}
	/*
	//Ohm--stat for dram_access
	dram_system.dram_controller[this_a.chan_id].rank[this_a.rank_id].r_p_info.dram_access++;
	dram_system.dram_controller[this_a.chan_id].rank[this_a.rank_id].r_p_gblinfo.dram_access++;
	*/
	this_t->next_c = transaction2commands(now,
			this_t->transaction_id,
			transaction_type,
			&(this_a)); 
	this_t->status = MEM_STATE_SCHEDULED;
	dram_system.dram_controller[this_a.chan_id].transaction_queue.transaction_count++;

	/* If the transaction selection policy is MOST/LEAST than you sort it */
	int trans_sel_policy = get_transaction_selection_policy(global_biu);
	if (trans_sel_policy == MOST_PENDING || trans_sel_policy == LEAST_PENDING) {
	  add_trans_pending_queue(this_a.chan_id,transaction_index);
	}
	
	if (transaction_type == MEMORY_WRITE_COMMAND) {
	  if (dram_system.dram_controller[this_t->address.chan_id].active_write_trans++ > 4) 
		dram_system.dram_controller[this_t->address.chan_id].active_write_flag = true;
	}
	return transaction_index;
}
Example #4
0
void z88_state::lcd_update(bitmap_ind16 &bitmap, UINT16 sbf, UINT16 hires0, UINT16 hires1, UINT16 lores0, UINT16 lores1, int flash)
{
	if (sbf == 0)
	{
		// LCD disabled
		bitmap.fill(0);
	}
	else
	{
		UINT8 *vram = convert_address(sbf<<11);

		for (int y=0; y<(Z88_SCREEN_HEIGHT>>3); y++)
		{
			int x = 0, c = 0;

			while (x < Z88_SCREEN_WIDTH)
			{
				UINT16 pen0, pen1;
				UINT8 *char_gfx;
				UINT8 byte0 = vram[(y * 0x100) + c];
				UINT8 byte1 = vram[(y * 0x100) + c + 1];

				// inverted graphics?
				if (byte1 & Z88_SCR_HW_REV)
				{
					pen0 = (byte1 & Z88_SCR_HW_GRY) ? 2 : 1;
					pen1 = 0;
				}
				else
				{
					pen0 = 0;
					pen1 = (byte1 & Z88_SCR_HW_GRY) ? 2 : 1;
				}

				if ((byte1 & Z88_SCR_HW_NULL) == Z88_SCR_HW_NULL)
				{
					// hidden
				}
				else if (!(byte1 & Z88_SCR_HW_HRS) || (((byte1 & Z88_SCR_HW_CURS) == Z88_SCR_HW_CURS)))
				{
					// low-res 6x8
					UINT16 ch = (byte0 | (byte1<<8)) & 0x1ff;

					if ((ch & 0x01c0) == 0x01c0)
					{
						ch &= 0x3f;

						char_gfx = convert_address(lores0<<9);
					}
					else
					{
						char_gfx = convert_address(lores1<<12);
					}

					char_gfx += (ch<<3);

					// cursor flash
					if (flash && (byte1 & Z88_SCR_HW_CURS) == Z88_SCR_HW_CURS)
						vh_render_6x8(bitmap, x,(y<<3), pen1, pen0, char_gfx);
					else
						vh_render_6x8(bitmap, x,(y<<3), pen0, pen1, char_gfx);

					// underline?
					if (byte1 & Z88_SCR_HW_UND)
						vh_render_line(bitmap, x, (y<<3), pen1);

					x += 6;
				}
				else if ((byte1 & Z88_SCR_HW_HRS) && !(byte1 & Z88_SCR_HW_REV))
				{
					// high-res 8x8
					UINT16 ch = (byte0 | (byte1<<8)) & 0x3ff;

					if (ch & 0x0100)
					{
						ch &= 0xff;
						char_gfx = convert_address(hires1<<11);
					}
					else
					{
						ch &= 0xff;
						char_gfx = convert_address(hires0<<13);
					}

					char_gfx += (ch<<3);

					// flash
					if ((byte1 & Z88_SCR_HW_FLS) && flash)
						pen0 = pen1 = 0;

					vh_render_8x8(bitmap, x,(y<<3), pen0, pen1, char_gfx);

					x += 8;
				}

				// every char takes 2 bytes
				c += 2;
			}
		}
	}
}
Example #5
0
static void *
convert_to_foreign(net_area_info *foreignArea,net_area_info *localArea,void *data)
{
	return convert_address(localArea,foreignArea,data);
}
Example #6
0
static inline void *
convert_to_local(net_area_info *foreignArea,net_area_info *localArea,void *data)
{
	return convert_address(foreignArea,localArea,data);
}