예제 #1
0
파일: zip_file.cpp 프로젝트: omegaluo/xlnt
void zip_file::load(std::istream &stream)
{
    reset();
    buffer_.assign(std::istreambuf_iterator<char>(stream), std::istreambuf_iterator<char>());
    remove_comment();
    start_read();
}
예제 #2
0
void swd::connection::start_read(const boost::system::error_code& e) {
	if (e) {
		return;
	}

	start_read();
}
예제 #3
0
void tcp_connection::handle_read(const boost::system::error_code &error, size_t bytes_transferred)
{
	if (!socket_.is_open() && !flags.eof)
	{
		set_eof();
	}

	if (flags.eof)
		return;

	if (error)
	{
		set_eof();
		do_close();
	}
	else if (bytes_transferred == 0)
	{
		set_eof();
		do_close();
	}
	else
	{
		rdata_size += bytes_transferred;

		if (parse_)
			parse_((pointer)this->shared_from_this());

		RFIFOFLUSH(this);

		start_read();
	}
}
예제 #4
0
파일: zip_file.cpp 프로젝트: omegaluo/xlnt
void zip_file::load(const std::vector<unsigned char> &bytes)
{
    reset();
    buffer_.assign(bytes.begin(), bytes.end());
    remove_comment();
    start_read();
}
예제 #5
0
void player_connection::handle_read( const boost::system::error_code error, const size_t len ) {

  if ( error && error != boost::asio::error::eof ) {
    //LOG_HIGH( SS, "player connection (" << _player_id << ") received an error that was not eof " );
    // ASSUME disconnected by mud
    return;
  }

  if( error == boost::asio::error::eof ) {
    LOG_LOW( SS, "player connection (" << _player_id << ") received eof ") ;
    _server->lost_link( _player_id );
    return;
  }
  
  // I think the handler won't get called until it reads *some* data, unless there is an error.
  // So if we get this far len shouldn't be 0
  assert( len > 0 );
  
  if ( len > 0 ) {
    //      LOG_LOW( SS, "read " << len );
  }
  
  for( int i = 0 ; i < len ; ++i) {
    _buf += _raw[i];
  }
  
  get_commands();
  
  start_read();
}
예제 #6
0
/* Implementation of the ADC driver API function: adc_read_sync. */
static int adc_nrfx_read_async(struct device *dev,
			       const struct adc_sequence *sequence,
			       struct k_poll_signal *async)
{
	adc_context_lock(&m_data.ctx, true, async);
	return start_read(dev, sequence);
}
예제 #7
0
serial_port::serial_port(event_loop* looper,const char* portname):
read_ev(this),
write_ev(this)
{
	port_handle = CreateFileA(portname, GENERIC_READ|GENERIC_WRITE, 0, 0, OPEN_EXISTING, FILE_FLAG_OVERLAPPED, 0);

	if(port_handle == INVALID_HANDLE_VALUE)
	{
		throw std::exception("port open failed");
	}

	HANDLE iocp_success = CreateIoCompletionPort(port_handle,looper->get_handle(),event_loop::EVENT_KEY,1);

	if(iocp_success != looper->get_handle())
	{
		//close the port handle before throwing
		CloseHandle(port_handle);

		throw std::exception("add port to iocp failed");
	}

	//ok set the timeouts
	COMMTIMEOUTS timeouts;
	memset((void*)&timeouts,0x00,sizeof(COMMTIMEOUTS));

	timeouts.ReadIntervalTimeout = 5;
	timeouts.ReadTotalTimeoutConstant = MAXDWORD;
	timeouts.ReadTotalTimeoutMultiplier = MAXDWORD;
	timeouts.WriteTotalTimeoutConstant = MAXDWORD;
	timeouts.WriteTotalTimeoutMultiplier = MAXDWORD;

	SetCommTimeouts(port_handle,&timeouts);

	start_read();
}
예제 #8
0
int SerialBase::read(uint16_t *buffer, int length, const event_callback_t& callback, int event, unsigned char char_match)
{
    if (serial_rx_active(&_serial)) {
        return -1; // transaction ongoing
    }
    start_read((void*)buffer, length, 16, callback, event, char_match);
    return 0;
}
예제 #9
0
int SerialBase::read(const Buffer& buffer, const event_callback_t& callback, int event, unsigned char char_match)
{
    if (serial_rx_active(&_serial)) {
        return -1; // transaction ongoing
    }
    start_read(buffer, 8, callback, event, char_match);
    return 0;
}
예제 #10
0
 void handle_read(const boost::system::error_code& ec, std::size_t n)
 {
     if(!ec) {
         std::string str;
         std::copy(buf_.begin(), buf_.begin()+n, std::back_inserter(str));
         handler_(str);
         start_read();
     }
 }
예제 #11
0
파일: copy_file.cpp 프로젝트: breese/afioc
    void process_open_output(const boost::system::error_code& error)
    {
        std::cout << __PRETTY_FUNCTION__ << ": " << error << std::endl;

        if (!error)
        {
            start_read();
        }
    }
예제 #12
0
void tcp_connection::start()
{
	boost::asio::ip::tcp::no_delay nodelay(true);
	socket_.set_option(nodelay);

	tag_ = ++tag_counter_;
	sessions_[tag_] = this->shared_from_this();

	start_read();
}
예제 #13
0
	void Client::message_callback(uint32_t length, std::shared_ptr<uint8_t> data, const boost::system::error_code& ec, const size_t nbytes)
	{
		BOOST_LOG_TRIVIAL(info) << "Message received.";

		message::MessageWrapper wrapper;
		wrapper.ParseFromArray(data.get(), length);

		event_map.fire(wrapper.type(), wrapper);
		start_read();
	}
예제 #14
0
// Acquires the reader_writer_lock for read.    If the lock is currently held by a writer,
// this reader will block and wait until the writers are done.
// Throws exception improper_lock when the context tries to acquire a reader_writer_lock
// that it already has write ownership of.
void reader_writer_lock::lock_read() {
    if (is_current_writer()) { // recursive lock attempt
        // we don't support writer->reader downgrade; throw exception
        tbb::internal::throw_exception(tbb::internal::eid_improper_lock);
    }
    else {
        scoped_lock_read a_reader_lock;
        start_read(&a_reader_lock);
    }
}
예제 #15
0
파일: am2301.c 프로젝트: cpetra/am2301
static int read_thread(void *data)
{
	int local_delay = 0;
	struct st_inf s;
	static struct st_inf sp;

        while (!kthread_should_stop()) {

		/*
		 * Do not sleep the whole chunk, otherwise if
		 *  the module is removed it will wait for that whole delay.
		 */
		if (local_delay != 0) {
			local_delay--;
			/* ToDo: Find a better interruptible delay implementation */
			wait_event_interruptible_timeout(_queue, 0, HZ);
			continue;
		}

		local_delay = _read_delay;
		_reads[0]++;

		if (start_read() != 0) {
			continue;
		}

		if (do_read_data(&s) != 0) {
			local_delay = SHORT_DELAY; /* Ignore this reading */
		}
		else {
			if (_reads[1] == 0) {
				local_delay = SHORT_DELAY;
				_reads[1]++ ;

			}
			else {
				if ((s.t - sp.t > 50) ||  /* 5 degrees difference */
				    (s.t - sp.t < -50) ||
				    (s.rh - sp.rh > 100) || /* or 10 RH differene */
				    (s.rh - sp.rh < -100))
				{
					/* Ignore this reading */
					local_delay = SHORT_DELAY;
				}
				else {
					sns = s;
					_reads[1]++;
				}
			}
			sp = s;
		}
        }
        return 0;
}
예제 #16
0
static int adc_stm32_read(struct device *dev,
			  const struct adc_sequence *sequence)
{
	struct adc_stm32_data *data = dev->driver_data;
	int error;

	adc_context_lock(&data->ctx, false, NULL);
	error = start_read(dev, sequence);
	adc_context_release(&data->ctx, error);

	return error;
}
예제 #17
0
 net_server_session::net_server_session(
     asio_network_provider& net, 
     const end_point& remote_addr,
     boost::asio::ip::tcp::socket& socket,
     std::shared_ptr<message_parser>& parser
     )
     : _net(net),
     rpc_server_session(net, remote_addr),
     net_io(remote_addr, socket, parser)
 {
     start_read();
 }
예제 #18
0
static int adc_stm32_read_async(struct device *dev,
				 const struct adc_sequence *sequence,
				 struct k_poll_signal *async)
{
	struct adc_stm32_data *data = dev->driver_data;
	int error;

	adc_context_lock(&data->ctx, true, async);
	error = start_read(dev, sequence);
	adc_context_release(&data->ctx, error);

	return error;
}
예제 #19
0
void tcp_connection :: start()
{
	serv->addToMap(shared_from_this(), usr->getNick());
	/* ajout du shared_ptr de this dans la map de client du serveur */
	
	std::string m_message;
	m_message = serv->getMOTD();
	
	boost::asio::async_write(m_socket, boost::asio::buffer(m_message),
		boost::bind(&tcp_connection::handle_write, shared_from_this(),
		boost::asio::placeholders::error) );
		
	start_read();
}
예제 #20
0
 void handle_write(const error_code& ec, std::size_t bytes)
 {
     _write_error = ec;
     _bytes_written += bytes;
     BOOST_LOG_TRIVIAL(trace) << "transferred: " << bytes << " bytes, total="
     << _bytes_written<< ", write_error: " << ec.message()
     << value::stdext::escape(_buffer.data(), _buffer.data() + bytes);
     
     if (_read_error or _write_error) {
         complete();
     }
     else {
         start_read();
     }
 }
예제 #21
0
/**
 * Add task.
 *
 * Basically:
 * 1. Make sure we're not being destroyed, and prevent destruction until we're done (dest_lock)
 * 2. Lock the task queue (unconditionally - no upper limit on number of tasks)
 * 3. Add a task
 * 4. Release the task queue lock and signal that the queue isn't empty (which one first?)
 * 5. Unlock the destruction lock (now we can kill the thread pool)
 */
int tpInsertTask(ThreadPool* tp, void (*func)(void *), void* param) {
	
	start_read(tp);				// Read the state, and generally prevent it's change
	if (tp->state != ALIVE) {	// If the thread pool is dying,
		end_read(tp);			// release the state for reading (no more writing will be done)
		return -1;				// and return indication of destruction.
	}
	
	// Try creating the task now, before locking the queue but after reading, because this
	// takes a long time so we don't want to prevent tasks from running. We're currently still
	// "reading" the thread pool state, but that's OK because a. it's a CREW lock so the threads
	// can read and see that the thread pool is a live and b. if a writer wants to write to the
	// state it's because the writer wants to destroy the thread pool - we want to prevent that
	// anyway at this point.
	Task* t = (Task*)malloc(sizeof(Task));
	if (!t) {
		end_read(tp);
		return -1;
	}
	t->func = func;
	t->param = param;
	
	// Editing the task queue now.
	// There's no danger of deadlock with thread acquiring this lock: If a thread isn't waiting
	// for a signal then all it does is read the state (we can allow that here even if we're
	// waiting for the task_lock) or do it's thing (dequeue or exit). Either way, it'll let go
	// of the lock eventually. We don't need to give the "add" function priority because the
	// worst case scenario is that it'll take some time to enqueue the task... But that's only
	// if the threads are busy, so the task won't get done anyway.
	pthread_mutex_lock(&tp->task_lock);
	PRINT("Adding a task, lock is locked\n");
	osEnqueue(tp->tasks,(void*)t);
	
	// Signal before releasing the lock - make a thread wait for the lock.
	pthread_cond_signal(&tp->queue_not_empty_or_dying);	
	PRINT("Task added, signal given, lock is locked\n");
	pthread_mutex_unlock(&tp->task_lock);
	PRINT("Task added, signal given, lock is unlocked\n");
	
	// Allow destruction of the thread pool (allow writing to pool->state)
	end_read(tp);
	
	return 0;
	
}
예제 #22
0
파일: zip_file.cpp 프로젝트: omegaluo/xlnt
void zip_file::save(std::ostream &stream)
{
    if(archive_->m_zip_mode == MZ_ZIP_MODE_WRITING)
    {
        mz_zip_writer_finalize_archive(archive_.get());
    }
    
    if(archive_->m_zip_mode == MZ_ZIP_MODE_WRITING_HAS_BEEN_FINALIZED)
    {
        mz_zip_writer_end(archive_.get());
    }
    
    if(archive_->m_zip_mode == MZ_ZIP_MODE_INVALID)
    {
        start_read();
    }
    
    append_comment();
    stream.write(buffer_.data(), buffer_.size());
}
예제 #23
0
파일: zip_file.cpp 프로젝트: omegaluo/xlnt
void zip_file::save(std::vector<unsigned char> &bytes)
{
    if(archive_->m_zip_mode == MZ_ZIP_MODE_WRITING)
    {
        mz_zip_writer_finalize_archive(archive_.get());
    }
    
    if(archive_->m_zip_mode == MZ_ZIP_MODE_WRITING_HAS_BEEN_FINALIZED)
    {
        mz_zip_writer_end(archive_.get());
    }
    
    if(archive_->m_zip_mode == MZ_ZIP_MODE_INVALID)
    {
        start_read();
    }
    
    append_comment();
    bytes.assign(buffer_.begin(), buffer_.end());
}
static BOOL finish_wait_rx (struct serial_win32* chan)
{
	BOOL	rok;
	DWORD	lastCount;	// undefined with WaitCommEvent.

	rok = GetOverlappedResult(
		chan->hPort,
		&chan->rxOverlapped, 
		&lastCount,
		FALSE);

	if (rok)
	{
		/* The wait is done, we have data in the OS buffer.  Start
		 * reading from the buffer into the application buffer now.
		 */
		chan->lastError = 0;
		return start_read(chan);

	} else
	{
		DWORD	ecode = GetLastError();

		if (ERROR_IO_PENDING == ecode || ERROR_IO_INCOMPLETE == ecode)
		{
			/* The wait is still pending.  Somehow the signal was sent
			 * when it wasn't ready.  Return FALSE to let the caller know
			 * no data is ready yet.
			 */
			chan->lastError = 0;
			return FALSE;
	
		} else
		{
			chan->lastError = ecode;
			return FALSE;
		}
	}
}
예제 #25
0
void swd::connection::start() {
	/* Save the ip of the httpd server in the request object. */
	boost::asio::ip::tcp::endpoint remote_endpoint;

	if (ssl_) {
		remote_endpoint = ssl_socket_.lowest_layer().remote_endpoint();
	} else {
		remote_endpoint = socket_.remote_endpoint();
	}

	remote_address_ = remote_endpoint.address();

	if (ssl_) {
		swd::log::i()->send(swd::notice, "Starting new ssl connection with "
		 + remote_address_.to_string());

		/**
		 * If this is a SSL connection we have to do a handshake before we can
		 * start reading.
		 */
		ssl_socket_.async_handshake(
			boost::asio::ssl::stream_base::server,
			strand_.wrap(
				boost::bind(
					&connection::start_read,
					shared_from_this(),
					boost::asio::placeholders::error
				)
			)
		);
	} else {
		swd::log::i()->send(swd::notice, "Starting new connection with "
		 + remote_address_.to_string());

		/* No SSL, directly start reading the input. */
		start_read();
	}
}
static BOOL start_wait_rx (struct serial_win32* chan)
{
	chan->rxMask = EV_RXCHAR;
	chan->rxState = RXSTATE_WAIT;

	ResetEvent(chan->eRxReady);
	if (WaitCommEvent(chan->hPort, &chan->rxMask, &chan->rxOverlapped))
	{
		/* If the event completes immediately, there must be data in the
		 * operating system buffer, so read it into the application
		 * buffer now.
		 */
		return start_read(chan);

	} else
	{
		DWORD	ecode = GetLastError();

		if (ERROR_IO_PENDING == ecode)
		{
			/* The RXCHAR event is pending.  We'll let it wait in the
			 * background and return back to the caller.  eRxReady will
			 * be signaled when there is at least one character in the
			 * serial port buffer.  Return FALSE to let the caller know
			 * no data is ready now.
			 */
			chan->lastError = 0;
			return FALSE;

		} else
		{
			chan->lastError = ecode;
			return FALSE;
		}
	}
}
예제 #27
0
void tcp_connection :: handle_read (const boost::system::error_code& error)
{
	if (!error)
	{
		std::string line;
		
		std::istream is(&buf);	// extraction du texte lu 
		std::getline(is, line, '\r');	// depuis le streambuf
		buf.consume(1);
		
	
		if ( line.size() > 512 ) // si msg trop long
		{
			std::string msg = "NOTICE ";
			msg += usr->getNick();
			msg += " :Message trop long ! 512 caracteres maximum\n";
		
			boost::asio::async_write(m_socket, boost::asio::buffer(msg),
			boost::bind(&tcp_connection::handle_write, shared_from_this(),
			boost::asio::placeholders::error) );
		}
		
		else
		{
			std::string to_write = header;
			to_write += line;
			to_write += "\n";
			std::cout <<to_write;
	
			serv->getMsgHandler()->parse(line, this);
			
		}
		
		start_read(); 	// réarmeement lecture
	}
}
예제 #28
0
 reader(mmstore &mms)
     : mms_(mms)
 {
     std::cerr << "reader starts\n";
     start_read();
 }
예제 #29
0
 void run()
 {
     start_read();
 }
예제 #30
0
player_connection::player_connection( socket_ptr socket, socket_server *server ) : _socket(socket), _player_id(next_player_id()), _server(server) { start_read(); }