`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.