boost::asio errors

Started by
4 comments, last by hplus0603 12 years, 11 months ago
the question is how can i convert this `boost::asio::async_read(socket_,boost::asio::buffer((char*)buffer, 1000),
boost::bind(&Connection::Receive, this,
boost::asio::placeholders::error));`
to int so i can check if i recived something?

#ifndef _CONNECTION_H_
#define _CONNECTION_H_

#include <boost/bind.hpp>
#include <boost/shared_ptr.hpp>
#include <boost/enable_shared_from_this.hpp>
#include <boost/asio.hpp>
#include <stdint.h>

class Connection
{
public:
Connection(boost::asio::io_service& io_service);
~Connection();
boost::asio::ip::tcp::socket& socket(){return socket_;}
void Send(uint8_t* buffer,int length);
bool Receive();

protected:
virtual void OnReceived(uint8_t* buffer, int len) = 0;

private:
boost::asio::ip::tcp::socket socket_;
};

#endif
--------------------------------------------------------------------------------------------------
#include "Connection.h"


Connection::Connection(boost::asio::io_service& io_service)
: socket_(io_service){
}

Connection::~Connection(){
}

void Connection::Send(uint8_t* buffer,int length){
boost::asio::async_write(socket_,boost::asio::buffer(buffer,length),
boost::bind(&Connection::Send, this,boost::asio::placeholders::error));
}

bool Connection::Receive(){
uint8_t* buffer = new uint8_t[1000];
int recvlen = boost::asio::async_read(socket_,boost::asio::buffer((char*)buffer, 1000),
boost::bind(&Connection::Receive, this,
boost::asio::placeholders::error));

if (recvlen <= 0) {
delete[] buffer;
return false;
}
this->OnReceived(buffer, recvlen);
delete [] buffer;
return true;
}

errors:

Error 1 error C2825: 'F': must be a class or namespace when followed by '::' e:\boost_1_46_1\boost_1_46_1\boost\bind\bind.hpp 69
Error 2 error C2039: 'result_type' : is not a member of '`global namespace'' e:\boost_1_46_1\boost_1_46_1\boost\bind\bind.hpp 69
Error 3 error C2146: syntax error : missing ';' before identifier 'type' e:\boost_1_46_1\boost_1_46_1\boost\bind\bind.hpp 69
Error 4 error C2208: 'boost::_bi::type' : no members defined using this type e:\boost_1_46_1\boost_1_46_1\boost\bind\bind.hpp 69
Error 5 error C1903: unable to recover from previous error(s); stopping compilation e:\boost_1_46_1\boost_1_46_1\boost\bind\bind.hpp 69
6 IntelliSense: a value of type "void" cannot be used to initialize an entity of type "int" d:\c++\ugs\common\connection.cpp 18
7 IntelliSense: the #endif for this directive is missing d:\c++\ugs\common\connection.h 1
8 IntelliSense: this declaration has no storage class or type specifier d:\c++\ugs\common\connection.h 26


whats wrong and how can i fix it thanks :) i appreciate it.
Advertisement

whats wrong and how can i fix it thanks :) i appreciate it.


You have angered the ancient gods. The evil has been awoken...


to int so i can check if i recived something?[/quote]
You can't, the call is asynchronous.

The result will be received in your callback OnReceived. The len there will be how much has been read.

See the tutorial on how to pass the recv parameters properly, I think your call is missing the length parameter, it only has error.

You have angered the ancient gods. The evil has been awoken...


ahahah LOL


You can't, the call is asynchronous.

The result will be received in your callback OnReceived. The len there will be how much has been read.

See the tutorial on how to pass the recv parameters properly, I think your call is missing the length parameter, it only has error.


aha I C, okey can you link me to the Tut. thnx for your answer :)
Just the calls.

Basic overview.

The rest.

Just the calls.

Basic overview.

The rest.


thnx i appreciate it.

the calls link u send me is for UPD is it the same for the TCP?
and it's an asynchronous while i needs it asynchronous coz it's a server for a gameserver :)

and it's an asynchronous while i needs it asynchronous coz it's a server for a gameserver :)




Actually, the list of the tutorials talks about sync and async TCP and UDP, so you can find what you need right there: http://www.boost.org/doc/libs/1_46_0/doc/html/boost_asio/tutorial.html
All the functions are documented in the reference: http://www.boost.org/doc/libs/1_46_0/doc/html/boost_asio/reference.html
If you know C++, and understand asynchronous/event-driven/callback-based/reactor-style programming (many names for the same thing), boost::asio can serve your C++ networking needs very well.
enum Bool { True, False, FileNotFound };

This topic is closed to new replies.

Advertisement