Example #1
0
void kmsgdump_write(char *fmt, ...)
{
	char buf[256] = {0,};
	va_list args;
	int len;

	va_start(args, fmt);
	len = vsprintf(buf, fmt, args);
	va_end(args);

	if((len>=256) || (len<0))
		buf[256-1] = '\n';

#if !defined (NM73131_0_BOARD)
#define LOG_TIME_STAMP //NM73131 is not support
#endif

#ifdef LOG_TIME_STAMP
	{
		char buf_t[30] = {0,};
		unsigned long rem_nsec;
		u64 ts = local_clock();
		
		rem_nsec = do_div(ts, 1000000000);
		sprintf(buf_t, "[%5lu.%06lu] ", (unsigned long)ts, rem_nsec / 1000);

		queue_write(&g_dumpqueue, (void*)buf_t, strlen(buf_t));
	}
#endif

	queue_write(&g_dumpqueue, (void*)buf, strlen(buf));
	wake_up(&atwilc_msgdump_waitqueue);

}
Example #2
0
size_t nrf_queue_in(nrf_queue_t const * p_queue,
                    void              * p_data,
                    size_t              element_count)
{
    ASSERT(p_queue != NULL);
    ASSERT(p_data != NULL);

    if (element_count == 0)
    {
        return 0;
    }

    CRITICAL_REGION_ENTER();

    if (p_queue->mode == NRF_QUEUE_MODE_OVERFLOW)
    {
        element_count = MIN(element_count, p_queue->size);
    }
    else
    {
        size_t available = nrf_queue_available_get(p_queue);
        element_count    = MIN(element_count, available);
    }

    queue_write(p_queue, p_data, element_count);

    CRITICAL_REGION_EXIT();

    return element_count;
}
Example #3
0
ret_code_t nrf_queue_write(nrf_queue_t const * p_queue,
                           void const        * p_data,
                           size_t              element_count)
{
    ret_code_t status = NRF_SUCCESS;

    ASSERT(p_queue != NULL);
    ASSERT(p_data != NULL);
    ASSERT(element_count <= p_queue->size);

    if (element_count == 0)
    {
        return NRF_SUCCESS;
    }

    CRITICAL_REGION_ENTER();

    if ((nrf_queue_available_get(p_queue) >= element_count)
     || (p_queue->mode == NRF_QUEUE_MODE_OVERFLOW))
    {
        queue_write(p_queue, p_data, element_count);
    }
    else
    {
        status = NRF_ERROR_NO_MEM;
    }

    CRITICAL_REGION_EXIT();

    return status;
}
Example #4
0
_U1RXInterrupt ()
{
	if (U1STAbits.OERR)
		U1STAbits.OERR = 0;
	while (U1STAbits.URXDA)
		if (!queue_is_full (&g_rx_queue))
			queue_write (&g_rx_queue, U1RXREG);

	IFS0bits.U1RXIF = 0;
}
Example #5
0
// write_error: queues a KSSL error message for sending.
void write_error(connection_state *state, DWORD id, BYTE error)
{
  int size = 0;
  BYTE *resp = NULL;

  kssl_error_code err = kssl_error(id, error, &resp, &size);
  log_error(id, error);
  if (err != KSSL_ERROR_INTERNAL) {
    queue_write(state, resp, size);
  }
}
Example #6
0
bool_e gfx_display_queue(gfx_display_t *gfxd, void *handle)
{
#ifdef GFX_DISPLAY_WRITE_TO_FILE
    if (gfxd)
    {
        size_t bytes = 0;
        uint32_t i = 0;
        // match the handle to the actually mapped pointer.
        for (i = 0; i < gfxd->numBuffers; i++)
        {
            if (handle == gfxd->handles[i])
            {
                uint32_t p,l,y = 0;
                image_t *img = gfxd->images[i];
                for (p = 0; p < img->numPlanes; p++)
                {
                    for (y = 0; y < img->plane[p].ydim/img->plane[p].yscale; y++)
                    {
                        i = (y * img->plane[p].ystride);
                        l = (img->plane[p].xdim / img->plane[p].xscale) * img->plane[p].xstride;
                        bytes += fwrite(&img->plane[p].ptr[i], 1, l, gfxd->fp);
                    }
                }
                DVP_PRINT(DVP_ZONE_VIDEO, "Wrote %zu bytes to file!\n", bytes);

                // write the pointer into the queue
                return queue_write(gfxd->returnq, true_e, &handle);
            }
        }
    }
    return false_e;
#else
    if (gfxd && handle)
    {
        // write the pointer into the queue
        return queue_write(gfxd->returnq, true_e, &handle);
    }
    else
        return false_e;
#endif
}
Example #7
0
void http_response_t::send(
		const std::string &payload,
		bool content_complete,
		bool close_after_write)
{
	if (content_complete && !keep_alive)
		close_after_write = true;

	auto connection = weak_connection.lock();
	if (connection != nullptr)
	{
		std::stringstream ss;
		if (!sent_headers)
		{
			ss << "HTTP/" << (keep_alive ? "1.1 ": "1.0 ") << code << " " << reason << "\r\n";
			for (auto &field_pair : fields)
			{
				ss << field_pair.first << ": " << field_pair.second << "\r\n";
			}
			if (payload.size() != 0)
			{
				ss << "Content-Type: " << content_type << "\r\n";
				//ss << "Transfer-Encoding: chunked\r\n";
				if (keep_alive)
					ss << "Connection: keep-alive\r\n";
				ss << "Content-Length: " << payload.size() << "\r\n";
				ss << "\r\n";
			}
		}

		//ss << std::hex << payload.size() << "\r\n";
		ss.write(payload.c_str(), payload.size());
		//ss << "\r\n";

		if (payload.size() != 0 || close_after_write)
			connection->queue_write(ss.str(), close_after_write);

		sent_headers = true;

		if (content_complete)
		{
			dlog(log_info, "request completed\n");
			connection->request_completed();
		}
	}
	else
	{
		dlog(log_warning, "%s bailed out on send\n");
	}
}
Example #8
0
void fcache_dump(DESC * d, int num)
{
    FBLOCK *fp;

    if ((num < 0) || (num > FC_LAST)) {
	return;
    }

    fp = fcache[num].fileblock;

    while (fp != NULL) {
	queue_write(d, fp->data, fp->hdr.nchars);
	fp = fp->hdr.nxt;
    }
}
Example #9
0
bool_e VisionCamFrameManager::Add( VisionCamFrame* frm )
{
    bool_e ret = false_e;
    FrameQueueNode_t *fr = NULL;

    if( frm && qFrames )
    {
//        Lock( frm, Alloc_e | Add_e );
        fr = new FrameQueueNode_t;
        fr->frame   = frm;

        ret = queue_write( qFrames, false_e, fr);
    }

    return ret;
}
Example #10
0
/**
 * def write(self, mask)
 */
static mp_obj_t class_queue_write(mp_obj_t self_in, mp_obj_t buf_in)
{
    struct class_queue_t *self_p;
    mp_buffer_info_t bufinfo;
    ssize_t res;

    self_p = MP_OBJ_TO_PTR(self_in);
    mp_get_buffer_raise(buf_in, &bufinfo, MP_BUFFER_READ);

    res = queue_write(&self_p->queue, bufinfo.buf, bufinfo.len);

    if (res <= 0) {
        nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError,
                                           "failed to write to queue"));
    }

    return (MP_OBJ_NEW_SMALL_INT(res));
}
SPAN_DECLARE(int) bell_mf_tx_put(bell_mf_tx_state_t *s, const char *digits, int len)
{
    size_t space;

    /* This returns the number of characters that would not fit in the buffer.
       The buffer will only be loaded if the whole string of digits will fit,
       in which case zero is returned. */
    if (len < 0)
    {
        if ((len = strlen(digits)) == 0)
            return 0;
    }
    if ((space = queue_free_space(&s->queue.queue)) < (size_t) len)
        return len - (int) space;
    if (queue_write(&s->queue.queue, (const uint8_t *) digits, len) >= 0)
        return 0;
    return -1;
}
Example #12
0
/**
  Finish program and output final statistics to screen.
*/
int finish ()
{
  FILE *fp;
  int i;
  
  // write reaction count to stdout
  print_reactions( TRUE );
  
  // output, that program has finished
  printf( "\nFinal time: %f", sys.tau );
  printf( "\nFinal volume: %f", sys.volume );
  printf("\n\n===============================================================================\n");
  printf("Run completed.\n");
//   log_exit();
  
  // check, if the state of the system has to be written to a file
  if( sys.output != NULL )
  {
    printf( "Write final state of the system to '%s'...\n", sys.output );
    
    if( (fp = fopen(sys.output, "w")) == NULL) 
    {
      printf("The file '%s' could not be created\n", sys.output);
      return EXIT_FAILURE;
    }
    
    fprintf( fp, "%f\t%d\t%d\t%f\tTime_Ncomp_QueueLength_LastDivision\n", 
             sys.tau, sys.Ncomp, queue_length(), sys.last_division 
           );
    
    for( i=0; i<sys.Ncomp; i++ )
      fprintf( fp, "%d\t%s\n", X[i], Xname[i] );
    
    if( queue_length() > 0 )
    {
      fprintf( fp, "Qindex_Qtime\n" );
      //queue_shift(sys.tau-sys.tau_init); //correct for previous shift
      queue_write( fp );
    }
    
    fclose( fp );
  }
  return EXIT_SUCCESS;
}
Example #13
0
// Write a single character to the output queue
static void
serial_putchar (char c)
{
	while (1)
	{
		DISABLE_INTERRUPTS
		if (!queue_is_full (&g_tx_queue))
			break;

		ENABLE_INTERRUPTS
		delay_loop_ms (1);
	}

	// Send straight away if we may
	if (queue_is_empty (&g_tx_queue) && !U1STAbits.UTXBF)
		U1TXREG = c;
	else
		queue_write (&g_tx_queue, c);
	ENABLE_INTERRUPTS
}
Example #14
0
arxstatus_t ImageBuffer::freeOnMatch(void *handle)
{
    ARX_PRINT(ARX_ZONE_API, "%s\n", __FUNCTION__);
    if (handle && handle == mImage.reserved) {
        if (mCam) {
            ARX_PRINT(ARX_ZONE_BUFFER, "imbuffer:%p, index:%d returning to camera mCamFrame:%p handle:%p\n", this, mIndex, mCamFrame, handle);
            if (mCamFrame) {
                mCam->returnFrame(mCamFrame);
            } else {
                ARX_PRINT(ARX_ZONE_WARNING, "freeOnMatch: no camera frame associated with this(%p) buffer!\n",this);
            }
        } else {
            bool ret = queue_write(mFreeQ, false_e, &mIndex);
            if (!ret) {
                ARX_PRINT(ARX_ZONE_BUFFER, "imbuff:%p: idx:%d error writing into free queue!\n", this, mIndex);
                return FAILED;
            }
        }
        return NOERROR;
    }
    return INVALID_ARGUMENT;
}
Example #15
0
static MemTxResult smmuv3_write_eventq(SMMUv3State *s, Evt *evt)
{
    SMMUQueue *q = &s->eventq;
    MemTxResult r;

    if (!smmuv3_eventq_enabled(s)) {
        return MEMTX_ERROR;
    }

    if (smmuv3_q_full(q)) {
        return MEMTX_ERROR;
    }

    r = queue_write(q, evt);
    if (r != MEMTX_OK) {
        return r;
    }

    if (smmuv3_q_empty(q)) {
        smmuv3_trigger_irq(s, SMMU_IRQ_EVTQ, 0);
    }
    return MEMTX_OK;
}
Example #16
0
/* ------------------------------------------------------------------------ *
 * Write either to the fd directly or to its queue.                         *
 * ------------------------------------------------------------------------ */
int io_write(int fd, const void *buf, size_t n)
{
  int ret;

  /* Catch invalid arguments */
  if(fd < 0) return -1;
  if(n == 0) return 0;

  /* fd is queued, write to the send queue */
  if(io_list[fd].control.sendq)
  {
    ret = queue_write(&io_list[fd].sendq, buf, n);

    if(io_list[fd].sendq.size)
      io_set_events(fd, IO_WRITE);

    return ret;
  }

  /* Write directly to fd */
  switch(io_list[fd].type)
  {
    case FD_SOCKET:
#ifdef HAVE_SSL
      if(io_list[fd].ssl)
        return ssl_write(fd, buf, n);
      else
#endif
        return syscall_send(fd, buf, n, 0);
    default:
    case FD_FILE:
    case FD_PIPE:
      return syscall_write(fd, buf, n);
  }

  return -1;
}
Example #17
0
// Put a file from the disk into the cache.  Synchronization required.
int put_cache(char* filename, char* data, int size) {

	cache_entry_t* entry = (cache_entry_t*)malloc(sizeof(cache_entry_t));
	
	// copy the filename to make sure that we own it.
	entry->filename = (char*)malloc( MAX_REQUEST * sizeof(char) );
	strncpy( entry->filename, filename, MAX_REQUEST );
	
	// do not copy data. the user of cache is responsible for it.
	entry->filedata = data;
	entry->file_size = size;
	
	
	while(queue_write(&cache_queue, entry) == -1) {
		fprintf(stderr, "Cache is full\n" );
		// remove an item from the queue (oldest/LRU)
		cache_entry_t* cached = queue_read(&cache_queue);
		// clean up cache entry.
		free( cached->filedata );
		free( cached->filename );
		free( cached );
	}
	return 0;
}
Example #18
0
/* ------------------------------------------------------------------------ *
 * Read as long as the system call fills the buffer and queue the data.     *
 * ------------------------------------------------------------------------ */
int io_queued_read(int fd)
{
  int ret = 0;
  size_t sz = 0;
  char buf[IO_READ_SIZE];

  syscall_errno = 0;

  do
  {
    switch(io_list[fd].type)
    {
      case FD_SOCKET:
#ifdef HAVE_SSL
        if(io_list[fd].ssl)
          ret = ssl_read(fd, buf, IO_READ_SIZE);
        else
#endif
          ret = syscall_recv(fd, buf, IO_READ_SIZE, 0);
        break;
      case FD_FILE:
      case FD_PIPE:
      default:
        ret = syscall_read(fd, buf, IO_READ_SIZE);
        break;
    }

    /* We got data, add it to the queue */
    if(ret > 0)
      sz += queue_write(&io_list[fd].recvq, buf, ret);
  }
  while(ret == IO_READ_SIZE);

  io_list[fd].status.onread = 1;
  io_list[fd].status.onwrite = 0;

/*  if(ret == 0 || (io_list[fd].type == FD_FILE && ret >= 0 && ret < IO_READ_SIZE))
  {
    io_list[fd].error = 0;
    io_list[fd].status.err = 1;

    return -1;
  }*/

#ifdef HAVE_SSL
/*  if(io_list[fd].ssl)
  {
    if(io_list[fd].error)
      return -1;
    else
      return 0;
  }
  else*/
  {
#endif
    if(ret < 0)
    {
      io_list[fd].error = syscall_errno;
      io_list[fd].status.err = 1;

      if(io_list[fd].error == EAGAIN)
      {
        io_list[fd].status.err = 0;
        return 0;
      }

      return -1;
    }
    else if(ret == 0)
    {
      io_list[fd].status.eof = 1;
    }
    else
    {
      io_list[fd].error = 0;
      io_list[fd].status.err = 0;
    }
#ifdef HAVE_SSL
  }
#endif

  return ret/* == 0 ? -1 : sz*/;
}
Example #19
0
File: thread.c Project: aosp/dvp
bool_e thread_unittest(int argc, char *argv[])
{
    uint32_t i, counter = 10;
    pingpongevent_t events;
    int numErrors = 0;
    bool_e verbose = false_e;
    option_t hash_opts[] = {
        {OPTION_TYPE_BOOL, &verbose, sizeof(bool_e), "-v", "--verbose", "Used to print out debugging information"},
    };
    msg_t msgs[] = {{3}, {9283}, {27}, {42}}; // last value == TEST_RET_VALUE
    msg_thread_t msgt;
    thread_t t;
    thread_ret_t r;

    option_process(argc, argv, hash_opts, dimof(hash_opts));

    if (verbose) {
        SOSAL_PRINT(SOSAL_ZONE_THREAD, "===THREAD TEST===\n");
    }

    // simple start, stop test
    t = thread_create(thread_test, &counter);
    r = thread_join(t);
    if (r != TEST_RET_VALUE)
        numErrors++;

    if (verbose) {
        SOSAL_PRINT(SOSAL_ZONE_THREAD, "===PING PONG TEST===\n");
    }

    // event test across threads
    event_init(&events.ping, false_e);
    event_init(&events.pong, false_e);

    t = thread_create(thread_test_events, &events);
    if (verbose) {
        SOSAL_PRINT(SOSAL_ZONE_THREAD, "Test is waiting for thread to wakeup!\n");
    }
    if (event_wait(&events.ping, 500))
    {
        if (verbose)
            SOSAL_PRINT(SOSAL_ZONE_THREAD, "Received Event from Thread!\n");
    }
    else
    {
        if (verbose)
            SOSAL_PRINT(SOSAL_ZONE_THREAD, "ERROR! Thread Message Timedout!\n");
    }
    if (verbose) SOSAL_PRINT(SOSAL_ZONE_THREAD, "Sending Event to Thread!\n");

    event_set(&events.pong);

    r = thread_join(t);
    SOSAL_PRINT(SOSAL_ZONE_THREAD, "=== THREAD JOIN exit = "THREAD_RET_FMT" ===\n", r);
    if (r != TEST_RET_VALUE)
        numErrors++;
    event_deinit(&events.ping);
    event_deinit(&events.pong);

    if (verbose) {
        SOSAL_PRINT(SOSAL_ZONE_THREAD, "===QUEUE TEST===\n");
    }

    msgt.msgs = queue_create(2, sizeof(msg_t));
    msgt.running = true_e;
    event_init(&msgt.signal, false_e);
    t = thread_create(thread_test_msgs, &msgt);
    if (verbose)
    {
        SOSAL_PRINT(SOSAL_ZONE_THREAD, "Waiting for thread to start!\n");
        SOSAL_PRINT(SOSAL_ZONE_THREAD, "Thread Started?(%s!)\n", (event_wait(&msgt.signal, 1000)?"true":"false"));
    }
    for (i = 0; i < dimof(msgs); i++) {
        if (queue_write(msgt.msgs, true_e, &msgs[i]) == false_e) {
            SOSAL_PRINT(SOSAL_ZONE_ERROR, "ERROR! Failed to write to queue!\n");
        } else {
            if (verbose) SOSAL_PRINT(SOSAL_ZONE_THREAD, "Wrote message "FMT_SIZE_T" to the Queue!\n", msgs[i].code);
        }
    }
    r = thread_join(t);
    SOSAL_PRINT(SOSAL_ZONE_THREAD, "=== THREAD JOIN exit = "THREAD_RET_FMT" ===\n", r);
    queue_destroy(msgt.msgs);
    event_deinit(&msgt.signal);

    if (verbose) {
        SOSAL_PRINT(SOSAL_ZONE_THREAD, "===THREAD TEST EXIT Errors=%d ===\n", numErrors);
    }

    if (numErrors > 0)
        return false_e;
    else
        return true_e;
}
Example #20
0
int safe_queue(gqueue *queue,gpointer data){
	dlog(0,"append\n");
	queue_write(queue,data);
	return 1;
}
Example #21
0
uint32_t io_multi_write(struct fqueue *fifoptr, const void *buf, uint32_t n)
{
  return queue_write(fifoptr, buf, n);
}
Example #22
0
// do_ssl: process pending data from OpenSSL and send any data that's
// waiting. Returns 1 if ok, 0 if the connection should be terminated
int do_ssl(connection_state *state)
{
  BYTE *response = NULL;
  int response_len = 0;
  kssl_error_code err;

  // First determine whether the SSL_accept has completed. If not then any
  // data on the TCP connection is related to the handshake and is not
  // application data.

  if (!state->connected) {
    if (!SSL_is_init_finished(state->ssl)) {
      int rc = SSL_do_handshake(state->ssl);
  
      if (rc != 1) {
        switch (SSL_get_error(state->ssl, rc)) {
        case SSL_ERROR_WANT_READ:
        case SSL_ERROR_WANT_WRITE:
          ERR_clear_error();
          return 1;
          
        default:
          ERR_clear_error();
          return 0;
        }
      }
    }

    state->connected = 1;
  }

  // Read whatever data needs to be read (controlled by state->need)

  while (state->need > 0) {
    int read = SSL_read(state->ssl, state->current, state->need);

    if (read <= 0) {
      int err = SSL_get_error(state->ssl, read);
      switch (err) {

        // Nothing to read so wait for an event notification by exiting
        // this function, or SSL needs to do a write (typically because of
        // a connection regnegotiation happening) and so an SSL_read
        // isn't possible right now. In either case return from this
        // function and wait for a callback indicating that the socket
        // is ready for a read.

      case SSL_ERROR_WANT_READ:
      case SSL_ERROR_WANT_WRITE:
        ERR_clear_error();
        return 1;

        // Connection termination

      case SSL_ERROR_ZERO_RETURN:
        ERR_clear_error();
        return 0;

        // Something went wrong so give up on connetion

      default:
        log_ssl_error(state->ssl, read);
        return 0;
      }
    }

    // Read some number of bytes into the state->current buffer so move that
    // pointer on and reduce the state->need. If there's still more
    // needed then loop around to see if we can read it. This is
    // essential because we will only get a single event when data
    // becomes ready and will need to read it all.

    state->need -= read;
    state->current += read;

    if (state->need > 0) {
      continue;
    }

    // All the required data has been read and is in state->start. If
    // it's a header then do basic checks on the header and then get
    // ready to receive the payload if there is one. If it's the
    // payload then the entire header and payload can now be
    // processed.

    if (state->state == CONNECTION_STATE_GET_HEADER) {
      err = parse_header(state->wire_header, &state->header);
      if (err != KSSL_ERROR_NONE) {
        return 0;
      }

      state->start = 0;

      if (state->header.version_maj != KSSL_VERSION_MAJ) {
        write_log(1, "Message version mismatch %02x != %02x",
                  state->header.version_maj, KSSL_VERSION_MAJ);
        write_error(state, state->header.id, KSSL_ERROR_VERSION_MISMATCH);
        clear_read_queue(state);
        free_read_state(state);
        set_get_header_state(state);
        return 1;
      }

      // If the header indicates that a payload is coming then read it
      // before processing the operation requested in the header

      if (state->header.length > 0) {
        if (!set_get_payload_state(state, state->header.length)) {
          write_log(1, "Memory allocation error");
          write_error(state, state->header.id, KSSL_ERROR_INTERNAL);
          clear_read_queue(state);
          free_read_state(state);
          set_get_header_state(state);
          return 1;
        }
        continue;
      }
    } if (state->state == CONNECTION_STATE_GET_PAYLOAD) {

      // Do nothing here. If we reach here then we know that the
      // entire payload has been read.

    } else {

      // This should be unreachable. If this occurs give up processing
      // and reset.

      write_log(1, "Connection in unknown state %d", state->state);
      free_read_state(state);
      set_get_header_state(state);
      return 1;
    }

    // When we reach here state->header is valid and filled in and if
    // necessary state->start points to the payload.

    uv_rwlock_rdlock(pk_lock);
    err = kssl_operate(&state->header, state->start, privates, &response,
                       &response_len);
    if (err != KSSL_ERROR_NONE) {
      log_err_error();
    } else  {
      queue_write(state, response, response_len);
    }
    uv_rwlock_rdunlock(pk_lock);

    // When this point is reached a complete header (and optional payload)
    // have been received and processed by the switch() statement above. So,
    // write the queued messages and then free the allocated memory and get
    // ready to receive another header.

    write_queued_messages(state);
    flush_write(state);

    free_read_state(state);
    set_get_header_state(state);

    // Loop around again in case there are multiple requests queued
    // up by OpenSSL. 
  }

  return 1;
}