Esempio n. 1
0
float eval(char *expr)
{
	STACK solution,temp;
	init_stack(&solution);init_stack(&temp);
	float value,operand1,operand2;
	while(*expr)
	{	
		if(!is_permitted(*expr)){
			fprintf(stderr,"error: invalid expression\n");
			exit(1);
		}

		if(is_digit(*expr))
			if(*expr == DECIMAL_PT)
				push(&temp, (float) DECIMAL_PT);
			else
				push(&temp, (float) (*expr - '0'));
		else if(is_delimiter(*expr)){
			if(!is_empty(&temp))
			push(&solution,process_data(&temp));
			else {
			expr++;continue;
			}
		}
		else {  
			operand2 = pop(&solution);
			operand1 = pop(&solution);
			value = operation(operand1,operand2,*expr);
			push(&solution,value);
		}
		expr++;
	}
	
	if(!is_empty(&temp))
		push(&solution,process_data(&temp));

	if(get_top(&solution)>0){
		printf("error: invalid postfix expression\n");
		exit(1);
	}
	return pop(&solution);
}				
Esempio n. 2
0
void RUDPSocket::process(uint8_t msg_id, uint16_t check_sum, BinStream& strm, const Inet_Addr& remote_addr)
{
	if(check_sum != check_sum_)
		return ;

	keeplive_count_ = 0;

	//地址学习
	if(remote_addr_ != remote_addr)
	{
		RUDP()->delete_peer_index(remote_rudp_id_, remote_addr_);
		remote_addr_ = remote_addr;
	}

	switch(msg_id)
	{
	case RUDP_DATA:
		process_data(strm, remote_addr);
		break;

	case RUDP_DATA_ACK:
		process_data_ack(strm, remote_addr);
		break;

	case RUDP_DATA_NACK:
		process_data_nack(strm, remote_addr);
		break;

	case RUDP_SYN2:
		process_syn2(strm, remote_addr);
		break;

	case RUDP_SYN_ACK:
		process_syn_ack(strm, remote_addr);
		break;

	case RUDP_FIN:
		process_fin(strm, remote_addr);
		break;

	case RUDP_FIN2:
		process_fin2(strm, remote_addr);
		break;

	case RUDP_KEEPALIVE:
		process_keeplive(strm, remote_addr);
		break;

	case RUDP_KEEPALIVE_ACK:
		process_keeplive_ack(strm, remote_addr);
		break;
	}
}
void PALThreadingTest::wait_for_data_to_process()
{
   pal::lockRecursiveMutex(m_condmut);
   while(!m_data_ready)
   {
      coreprintln("Entering conditional wait...");
      pal::conditionalWaitRecursive(m_cond, m_condmut);
      coreprintln("Leaving conditional wait!");
   }
   process_data();
   pal::unlockRecursiveMutex(m_condmut);
}
Esempio n. 4
0
static void input_handler_done (PacketProtoDecoder *enc, int data_len)
{
    ASSERT(data_len > 0)
    ASSERT(data_len <= enc->buf_size - (enc->buf_start + enc->buf_used))
    DebugObject_Access(&enc->d_obj);
    
    // update buffer
    enc->buf_used += data_len;
    
    // process data
    process_data(enc);
    return;
}
Esempio n. 5
0
int main( int argc, char * argv[] ){

	std::ifstream datafile(argv[1]);

	std::string line;

	while( std::getline( datafile, line ) ){

		process_data( line );
	}

	return 0;
}
Esempio n. 6
0
static void processing_data(struct net_pkt *pkt, bool is_loopback)
{
	switch (process_data(pkt, is_loopback)) {
	case NET_OK:
		NET_DBG("Consumed pkt %p", pkt);
		break;
	case NET_DROP:
	default:
		NET_DBG("Dropping pkt %p", pkt);
		net_pkt_unref(pkt);
		break;
	}
}
Esempio n. 7
0
static inline
uint8_t process ( bt_addresses * addresses )
{
    talloc_buffer * buffer = addresses->buffer;
    uint8_t * buf          = talloc_buffer_get ( buffer );
    size_t length          = talloc_buffer_get_length ( buffer );
    size_t current_length  = length;
    struct nlmsghdr * data;

    bool process_failed  = false;
    for ( data = ( struct nlmsghdr * ) buf; NLMSG_OK ( data, current_length ); data = NLMSG_NEXT ( data, current_length ) ) {
        switch ( data->nlmsg_type ) {
        case RTM_NEWADDR:
            if ( process_data ( addresses, data, true ) != 0 ) {
                process_failed = true;
            }
            break;
        case RTM_DELADDR:
            if ( process_data ( addresses, data, false ) != 0 ) {
                process_failed = true;
            }
            break;
        case NLMSG_DONE:
            if ( talloc_buffer_trim ( buffer ) != 0 ) {
                process_failed = true;
            }
            break;
        }
    }

    if ( talloc_buffer_readed ( buffer, length - current_length ) != 0 ) {
        return 1;
    }
    if ( process_failed ) {
        return 2;
    }

    return 0;
}
Esempio n. 8
0
int main(int argc, char *argv[])
{
	int dvrfd, tsfd;
	unsigned int pid;
	char *dmxdev = "/dev/dvb/adapter0/demux0";
	char *dvrdev = "/dev/dvb/adapter0/dvr0";
	int i;
	char *chkp;

	if (argc < 3)
		usage();

	if (getenv("DEMUX"))
		dmxdev = getenv("DEMUX");
	if (getenv("DVR"))
		dvrdev = getenv("DVR");

	fprintf(stderr, "using '%s' and '%s'\n"
		"writing to '%s'\n", dmxdev, dvrdev, argv[1]);
	tsfd = open(argv[1], O_WRONLY | O_CREAT | O_TRUNC, 0664);
	if (tsfd == -1) {
		perror("cannot write output file");
		return 1;
	}

	dvrfd = open(dvrdev, O_RDONLY);
	if (dvrfd == -1) {
		perror("cannot open dvr device");
		return 1;
	}

	if (getenv("BUF_SIZE") && ((BUF_SIZE = strtoul(getenv("BUF_SIZE"), NULL, 0)) > 0))
		fprintf(stderr, "BUF_SIZE = %lu\n", BUF_SIZE);

	for (i = 2; i < argc; i++) {
		pid = strtoul(argv[i], &chkp, 0);
		if (pid > 0x2000 || chkp == argv[i])
			usage();
		fprintf(stderr, "adding filter for PID 0x%04x\n", pid);
		//FIXME: stop & close filters later...
		if (add_filter(pid, dmxdev) != 0)
			return 1;
	}

	for (;;) {
		process_data(dvrfd, tsfd);
	}

	close(dvrfd);
	return 0;
}
Esempio n. 9
0
int main(int argc, char **argv) {
    FILE *datafile = NULL;

    /* find out how we got invoked and deal with it */
    switch (argc) {
        case 1:
            /* only one program argument (the program name) */ 
            /* just equate stdin with our datafile */
            datafile = stdin;        
            break;

        case 2:
            /* two arguments: program name and input file */
            /* open the file, assign to datafile */
            datafile = fopen(argv[1], "r");
            if (datafile == NULL) {
                printf("Unable to open file %s: %s\n", argv[1], strerror(errno));
                exit(-1);
            }
            break;

        default:
            /* more than two arguments?  throw hands up in resignation */
            usage(argv[0]);
    }

    /* 
     * you should be able to just read from datafile regardless 
     * whether it's stdin or a "real" file.
     */
    process_data(datafile);
    fclose(datafile);
	//time stuff;

	printf("*** List Contents End ***\n");
    	struct timeval user; 
    	struct timeval sys;        
    	struct rusage usage;
	//redundancy case
	if(getrusage(RUSAGE_SELF, &usage) != 0) {
        	printf("rusage children error: %s", strerror(errno));
        	exit(-1);
    	}
    	user = usage.ru_utime;
    	sys = usage.ru_stime;
	printf("User time: %f\n", (double)user.tv_sec		+(double)user.tv_usec/1000000);
    	printf("System time: %f\n", (double)sys.tv_sec+(double)sys.tv_usec/1000000);


    return 0;
}
Esempio n. 10
0
int main( int argc, char **argv ) {
char 		*rfile, *Rfile, *Mdirs;
int			c;

	rfile = Rfile = Mdirs = NULL;
	while ((c = getopt(argc, argv, "L:r:M:R:")) != EOF) {
		switch (c) {
			case 'h':
				usage(argv[0]);
				exit(0);
				break;
				break;
			case 'L':
				if ( !InitLog("argv[0]", optarg) )
					exit(255);
				break;
			case 'r':
				rfile = optarg;
				if ( strcmp(rfile, "-") == 0 )
					rfile = NULL;
				break;
			case 'M':
				Mdirs = optarg;
				break;
			case 'R':
				Rfile = optarg;
				break;
			default:
				usage(argv[0]);
				exit(0);
		}
	}

	if ( rfile && Rfile ) {
		fprintf(stderr, "-r and -R are mutually exclusive. Please specify either -r or -R\n");
		exit(255);
	}
	if ( Mdirs && !(rfile || Rfile) ) {
		fprintf(stderr, "-M needs either -r or -R to specify the file or file list. Add '-R .' for all files in the directories.\n");
		exit(255);
	}

	InitExtensionMaps(&extension_map_list);

	SetupInputFileSequence(Mdirs, rfile, Rfile);

	process_data();


	return 0;
}
Esempio n. 11
0
/* print output */
int telnet_session_print(struct telnet_session_s *t, const char *s)
{
	int len;
	int amt_printed;

	daemon_assert(invariant(t));

	len = strlen(s);
	if (len == 0) {
		daemon_assert(invariant(t));
		return 1;
	}

	amt_printed = 0;
	do {
		if ((t->out_errno != 0) || (t->out_eof != 0)) {
			daemon_assert(invariant(t));
			return 0;
		}
		while ((amt_printed < len) && (t->out_buflen < BUF_LEN)) {
			daemon_assert(s[amt_printed] != '\0');
			add_outgoing_char(t, s[amt_printed]);
			amt_printed++;
		}
		process_data(t, 1);
	} while (amt_printed < len);

	while (t->out_buflen > 0) {
		if ((t->out_errno != 0) || (t->out_eof != 0)) {
			daemon_assert(invariant(t));
			return 0;
		}
		process_data(t, 1);
	}

	daemon_assert(invariant(t));
	return 1;
}
Esempio n. 12
0
/* server_loop: continously receive and process data */
void TwitchBot::server_loop()
{
	char buf[BUFFER_SIZE];
	char *pos, *s;
	int bytes, shift;
	size_t len;

	pos = buf;
	len = 0;
	/* continuously receive data from server */
	while (1) {
		shift = 0;
		if ((bytes = cread(&client, pos, BUFFER_SIZE - len)) < 0) {
			perror("read");
			fprintf(stderr, "LynxBot exiting.\n");
			disconnect();
			break;
		} else if (bytes == 0) {
			continue;
		}
		pos += bytes;
		len += bytes;
		if (len < BUFFER_SIZE - 1) {
			/* keep reading until full message has been received */
			if (*(pos - 1) != '\n' && *(pos - 2) != '\r')
				continue;
		} else {
			/* end string at last newline, shift rest to front */
			s = pos;
			while (*--s != '\n' && len)
				--len;
			*s = '\0';
			shift = 1;
		}

		printf("[RECV] %s\n", buf);
		process_data(buf);
		if (shift) {
			len = BUFFER_SIZE - 1 - len;
			pos = buf + len;
			memmove(buf, s + 1, len + 1);
		} else {
			pos = buf;
			len = 0;
		}

		if (!bot_connected)
			break;
	}
}
Esempio n. 13
0
static void __attribute__((__interrupt__(TIMER0_A0_VECTOR))) timer0_a0_isr(void)
#endif
{
        MPU6050_read(MPU6050_ACCEL_XOUT_H, sizeof(ga_data));

        // Reverse byte ordering of accel/gyro data
        SWAP (ga_data.reg.x_accel_h, ga_data.reg.x_accel_l);
        SWAP (ga_data.reg.y_accel_h, ga_data.reg.y_accel_l);
        SWAP (ga_data.reg.z_accel_h, ga_data.reg.z_accel_l);
        SWAP (ga_data.reg.x_gyro_h, ga_data.reg.x_gyro_l);
        SWAP (ga_data.reg.y_gyro_h, ga_data.reg.y_gyro_l);
        SWAP (ga_data.reg.z_gyro_h, ga_data.reg.z_gyro_l);

        process_data();

}
Esempio n. 14
0
File: main.c Progetto: 7be/DSV2Lab
void main(void)
{
	// initialize AD1836
	start_AD1836();
		
	// loop forever
	while(1) {
		idle();				// go asleep and wake up when external interrupt and ISR have been
		
		if (cNewSample) {
			cNewSample = 0;
			process_data();
		}
	}
		
}
Esempio n. 15
0
/*
 * This routine will poll for a received Input report, process it
 * and send an Output report to the host.
 * Both directions use interrupt transfers.
 * The ownership of the USB buffers will change according
 * to the required operation.
 */
void send_receive (void)
{
	static int usb_state = 'r';
	static USB_HANDLE last_transmit = 0;
	static USB_HANDLE last_receive = 0;

	switch (usb_state) {
	case 'r':
	   	if (! HIDRxHandleBusy (last_receive)) {
			// The CPU owns the endpoint. Start receiving data.
			last_receive = HIDRxPacket (HID_EP,
				(unsigned char*) &hid_report_out,
                                HID_INT_OUT_EP_SIZE);
			usb_state = 'p';
		}
		break;
	case 'p':
		if (! HIDRxHandleBusy (last_receive)) {
			// The CPU owns the endpoint.
			if (last_receive->CNT > 0) {
				// Data was received. Copy it to the output buffer for sending.
				process_data();

				// Ready to transmit the received data back to the host.
				usb_state = 't';
			} else {
				// No data was received. Return to checking for new received data.
				usb_state = 'r';
			}
		}
		break;
	case 't':
		if (! HIDTxHandleBusy (last_transmit)) {
			// The CPU owns the endpoint. Start sending data.
			last_transmit = HIDTxPacket (HID_EP,
				(unsigned char*) &hid_report_in,
				HID_INPUT_REPORT_BYTES);

			// Return to checking for new received data.
			usb_state = 'r';
		}
		break;
	default:
	        // Cannot happen.
		break;
	}
}
Esempio n. 16
0
LIBDE265_API de265_error de265_decode_data(de265_decoder_context* de265ctx, const void* data, int len)
{
  decoder_context* ctx = (decoder_context*)de265ctx;


  if (len==0) {
    ctx->end_of_stream = true;
  }


  // process the data that is still pending for input

  if (ctx->pending_input_data.size > 0) {

    de265_error err = de265_decode_pending_data(de265ctx);

    // if something went wrong, or more data is pending
    // -> append new input data to pending-input buffer
    if (err != DE265_OK || ctx->pending_input_data.size!=0) {
      if (len>0) {
        rbsp_buffer_append(&ctx->pending_input_data, (const uint8_t*)data,len);
      }

      return err;
    }
  }


  de265_error err = DE265_OK;
  int nBytesProcessed = 0;

  if (has_free_dpb_picture(ctx)) {
    err = process_data(ctx,(const uint8_t*)data,len, &nBytesProcessed);
  }

  if (nBytesProcessed != len) {
    //printf("%d %d\n",nBytesProcessed,len);

    // save remaining bytes

    assert(ctx->pending_input_data.size==0); // assume pending-input buffer is empty
    rbsp_buffer_append(&ctx->pending_input_data, (const uint8_t*)data+nBytesProcessed, len-nBytesProcessed);
  }

  return err;
}
Esempio n. 17
0
int main (int argc, char **argv)
{
	int size;
	int id;
	double t_start;
	double t_end;
	image *photo;
	int localsize, totalsize, maxRGB;
	unsigned char * localdata;
	
	MPI_Init (&argc, &argv);
	MPI_Comm_size (MPI_COMM_WORLD, &size);
	MPI_Comm_rank (MPI_COMM_WORLD, &id);

	if (id == 0) {
		photo = setup (argc, argv);
		totalsize = photo->width * photo->height * 3;
		localsize = totalsize / size;
		maxRGB = photo->max_value;
	}
	t_start = MPI_Wtime();
	
	/* broadcast max rgb value */
	MPI_Bcast(&maxRGB, 1, MPI_INT, 0, MPI_COMM_WORLD);
	
	/* broadcast local data size */
	MPI_Bcast(&localsize, 1, MPI_INT, 0, MPI_COMM_WORLD);
	
	localdata = (unsigned char *) malloc(localsize);
	
	MPI_Scatter(photo->data, localsize, MPI_BYTE, localdata, localsize, MPI_BYTE, 0, MPI_COMM_WORLD);
	
	process_data(localdata, maxRGB, localsize);
	
	MPI_Gather(localdata, localsize, MPI_BYTE, photo->data, localsize, MPI_BYTE, 0, MPI_COMM_WORLD);
	
	t_end = MPI_Wtime();
	
	if (id == 0) {
		cleanup (photo, argv);
		printf("p = %d, elapsed time = %.2lf s.", size, t_end - t_start);
	}	
	
	MPI_Finalize ();
	return 0;
}
Esempio n. 18
0
static void process_config(struct net_pkt *pkt)
{
	struct net_buf *buf = net_buf_frag_last(pkt->frags);
	u8_t cmd = net_buf_pull_u8(buf);

	SYS_LOG_DBG("Process config %c", cmd);

	switch (cmd) {
	case 'S':
		process_data(pkt);
		break;
	case 'C':
		set_channel(net_buf_pull_u8(buf));
		break;
	default:
		SYS_LOG_ERR("Unhandled cmd %u", cmd);
	}
}
Esempio n. 19
0
static int
process_file(const char *file_name, size_t offset, char *toString)
{
    void *FileData;
    size_t FileSize;
    int res = 1;

    FileData = load_file(file_name, &FileSize);
    if (!FileData)
    {
        l2l_dbg(0, "An error occured loading '%s'\n", file_name);
    }
    else
    {
        res = process_data(FileData, offset, toString);
        free(FileData);
    }
    return res;
}
Esempio n. 20
0
int dhash_unpack_chord_data(Header *header, DHashPacketArgs *args, Data *msg,
                            Node *from)
{
    fprintf(stderr, "received routing packet\n");
    ChordServer *srv = args->chord_args.srv;
    DHash *dhash = args->dhash;

    int type = dispatcher_get_type(msg->data.data, msg->data.len);
    dispatcher_push_arg(dhash->chord_dispatcher, type, srv);

    int process_ret;
    int ret = dispatch_packet(dhash->chord_dispatcher, msg->data.data,
                              msg->data.len, from, &process_ret);

    dispatcher_pop_arg(dhash->chord_dispatcher, type);

    if (!ret || process_ret)
        process_data(header, (ChordPacketArgs *)args, msg, from);

    return 0;
}
Esempio n. 21
0
void				setup_mesh_faces(t_obj_data *obj_data,
		t_face_list *face_list)
{
	int				i;
	int				*ids;
	int				uv_count;

	i = 0;
	obj_data->indice_count = obj_data->face_count * 3;
	obj_data->indices = (GLushort*)malloc(sizeof(GLushort)
			* obj_data->indice_count);
	obj_data->vertices = (t_vertex*)malloc(sizeof(t_vertex)
			* obj_data->indice_count);
	uv_count = obj_data->uv_count > 0 ? obj_data->uv_count : 1;
	ids = (int*)malloc(sizeof(int) * obj_data->vertex_count * uv_count);
	while (i < obj_data->vertex_count * uv_count)
		ids[i++] = -1;
	obj_data->vertex_count = process_data(obj_data, uv_count, face_list, ids);
	free(ids);
	display_info(obj_data);
}
Esempio n. 22
0
File: main.cpp Progetto: att/uwin
void process_table(table_input &in)
{
  options *opt = 0;
  format *form = 0;
  table *tbl = 0;
  if ((opt = process_options(in)) != 0 
      && (form = process_format(in, opt)) != 0
      && (tbl = process_data(in, form, opt)) != 0) {
    tbl->print();
    delete tbl;
  }
  else {
    error("giving up on this table");
    while (in.get() != EOF)
      ;
  }
  delete opt;
  delete form;
  if (!in.ended())
    error("premature end of file");
}
Esempio n. 23
0
int thor_handle(void)
{
	int ret;

	/* receive the data from Host PC */
	while (1) {
		thor_set_dma(thor_rx_data_buf, sizeof(struct rqt_box));
		ret = thor_rx_data();

		if (ret > 0) {
			ret = process_data();
			if (ret < 0)
				return ret;
		} else {
			printf("%s: No data received!\n", __func__);
			break;
		}
	}

	return 0;
}
Esempio n. 24
0
static void process_packet(void *packet, const int len)
{
	struct ieee80211_frame *wh = (struct ieee80211_frame *) packet;

#if 0
	printf("GOT %d\n", len);
	hexdump(packet, len);
#endif

	if (len < (int) sizeof(*wh)) return;

	switch (wh->i_fc[0] & IEEE80211_FC0_TYPE_MASK)
	{
		case IEEE80211_FC0_TYPE_MGT:
			switch (wh->i_fc[0] & IEEE80211_FC0_SUBTYPE_MASK)
			{
				case IEEE80211_FC0_SUBTYPE_BEACON:
					process_beacon(wh, len);
					break;

				case IEEE80211_FC0_SUBTYPE_ASSOC_REQ:
					grab_hidden_ssid(wh->i_addr3, wh, len, 2 + 2);
					break;

				case IEEE80211_FC0_SUBTYPE_REASSOC_REQ:
					grab_hidden_ssid(wh->i_addr3, wh, len, 2 + 2 + 6);
					break;

				case IEEE80211_FC0_SUBTYPE_PROBE_RESP:
					grab_hidden_ssid(wh->i_addr3, wh, len, 8 + 2 + 2);
					break;
			}
			break;

		case IEEE80211_FC0_TYPE_DATA:
			process_data(wh, len);
			break;
	}
}
bool ftrace_decode_binary_dispatch_file::process(const char * file)
{
	fd = fopen(file, "r");
	if (fd == NULL)
		return false;
	/* do basic check to know if it's a real/valid binary data file */
	do {
		int i;
		long long sum = 0;
		if (fread(&i, sizeof(int), 1, fd) <= 0)
			break;
		if (i != 0)
			break; /* if first byte is 0 it's definitivilly not an ASCII file !*/
		if (fseek(fd, 16, SEEK_SET) != 16)
			break;
		if (fread(&cpu_nb, sizeof(int), 1, fd) <= 0)
			break;
		if (fread(&cpu_size[0], sizeof(int), cpu_nb, fd) <= 0)
			break;
		if ((cpu_nb <= 0) || (cpu_nb >= cpu_max))
			break;
		for (i = 0; i < cpu_nb; i++)
		{
			cpu_size_current[i] = 0;
			sum += cpu_size[i];
		}
		if ((sum & (page_size - 1)) != 0)
			break;
		/* size of file is sum cpu_size + page_size, since the first page_size data
			contains the cpu_nb/cpu_size[] */
		if (fseek(fd, sum, SEEK_SET) != sum)
			break;
		process_data();
		fclose(fd);
		return true;
	} while (0);
	fclose(fd);
	return false;
}
Esempio n. 26
0
/*
 * task_fileiolog_read -- reads from the log in the FILEIO mode
 */
int
task_fileiolog_read(void *arg)
{
	int32_t rand_number;
	struct thread_info *thread_info = arg;
	size_t vec_size = thread_info->vec_size;
	size_t el_size = thread_info->el_size;
	int fd = *(int *)thread_info->hndl;

	if (thread_info->rand_state != NULL) {
		random_r(thread_info->rand_state, &rand_number);
		vec_size = rand_number % vec_size + MIN_VEC_SIZE;
		el_size = rand_number % el_size + MIN_EL_SIZE;
	}

	thread_info->buf_ptr = 0;
	char buf[vec_size * el_size];
	while (pread(fd, buf, vec_size * el_size, thread_info->buf_ptr) != 0) {
		process_data(buf, vec_size * el_size, thread_info);
	}

	return EXIT_SUCCESS;
}
Esempio n. 27
0
/*! \brief The callback function that is called when new audio data becomes available 
 *
 * @author Eric des Courtis
 * @param bug A reference to the media bug.
 * @param user_data The session information for this call.
 * @param type The switch callback type.
 * @return The success or failure of the function.
 */
static switch_bool_t vmd_callback(switch_media_bug_t *bug, void *user_data, switch_abc_type_t type)
{
	vmd_session_info_t *vmd_info;
	switch_codec_t *read_codec;
	switch_frame_t *frame;

	vmd_info = (vmd_session_info_t *) user_data;
	if (vmd_info == NULL) {
		return SWITCH_FALSE;
	}

	switch (type) {

	case SWITCH_ABC_TYPE_INIT:
		read_codec = switch_core_session_get_read_codec(vmd_info->session);
		vmd_info->vmd_codec.rate = read_codec->implementation->samples_per_second;
		vmd_info->vmd_codec.channels = read_codec->implementation->number_of_channels;
		break;

	case SWITCH_ABC_TYPE_READ_PING:
	case SWITCH_ABC_TYPE_CLOSE:
	case SWITCH_ABC_TYPE_READ:
	case SWITCH_ABC_TYPE_WRITE:
	case SWITCH_ABC_TYPE_TAP_NATIVE_READ:
	case SWITCH_ABC_TYPE_TAP_NATIVE_WRITE:
		break;

	case SWITCH_ABC_TYPE_READ_REPLACE:
		frame = switch_core_media_bug_get_read_replace_frame(bug);
		return process_data(vmd_info, frame);

	case SWITCH_ABC_TYPE_WRITE_REPLACE:
		break;
	}

	return SWITCH_TRUE;
}
Esempio n. 28
0
static void
distribution_read(void)
{
    int i, n;
    struct sockaddr_in6 addr;
    socklen_t len = sizeof(addr);
    char addrstr[INET6_ADDRSTRLEN];

    memset(&addr, 0, sizeof(addr));
    memset(buf, 0, c_bufsize);

    for (i = 0; i < c_max_read; i++) {
        n = recvfrom(recv_fd, buf, c_bufsize, 0,
                     (struct sockaddr *) &addr, &len);

        if (n < 0) {
            if (EAGAIN == errno)
                return;
            else
                quit("recvfrom failed: %s\n", strerror(errno));
        }

        if (addr.sin6_family == AF_INET) {
            struct sockaddr_in *in4 = (struct sockaddr_in *) &addr;
            inet_ntop(AF_INET, (void *) &in4->sin_addr,
                      addrstr, len);
        } else if (addr.sin6_family == AF_INET6) {
            inet_ntop(AF_INET6, (void *) &addr.sin6_addr,
                      addrstr, len);
        }

        if (c_debug)
            fprintf(stderr, "Read %d bytes from %s\n", n, addrstr);

        process_data(buf, n, addrstr);
    }
}
Esempio n. 29
0
File: trapper.c Progetto: Shmuma/z
void	child_trapper_main(int i)
{
	int count, history;
	queue_entry_t entry;

	zabbix_log( LOG_LEVEL_DEBUG, "In child_trapper_main()");
	zabbix_log( LOG_LEVEL_WARNING, "server #%d started [Trapper]", i);

	/* initialize queue */
	queue_fd = queue_get_queue_id (i, 0);

	/* initialize metrics */
	key_values = metric_register ("trapper_data_values",  i);
	key_skipped = metric_register ("trapper_data_skipped_bytes",  i);
	metric_update (key_skipped, mtr_skipped);

	DBconnect(ZBX_DB_CONNECT_NORMAL);

	for(;;)
	{
		zbx_setproctitle("Trapper waiting for new queue data");

		/* First we try to get data from primary queue */
		if (trapper_dequeue_request (&entry)) {
			zbx_setproctitle("processing queue data block");

			if (!strcmp (entry.key, "profile"))
				process_profile_value (entry.server, entry.error);
			process_data (0, entry.ts, entry.server, entry.key, entry.value,
				      entry.error, entry.lastlogsize, entry.timestamp,
				      entry.source, entry.severity);
			free (entry.buf);
		}
	}
	DBclose();
}
Esempio n. 30
0
/* initialize a telnet session */
void telnet_session_init(struct telnet_session_s *t, FILE_DESCRIPTOR_OR_ERROR in, FILE_DESCRIPTOR_OR_ERROR out)
{
	daemon_assert(t != NULL);
	daemon_assert(in >= 0);
	daemon_assert(out >= 0);

	t->in_fd = in;
	t->in_errno = 0;
	t->in_eof = 0;
	t->in_take = t->in_add = 0;
	t->in_buflen = 0;

	t->in_status = NORMAL;

	t->out_fd = out;
	t->out_errno = 0;
	t->out_eof = 0;
	t->out_take = t->out_add = 0;
	t->out_buflen = 0;

	process_data(t, 0);

	daemon_assert(invariant(t));
}