problem with boost sockets

Hi,
im getting seg fault on boost::asio::ip::tcp::acceptor.
my backtrace:
1
2
3
4
5
6
7
8
9
10
11
12
13
Program received signal SIGSEGV, Segmentation fault.
0x004b0a1c in boost::asio::socket_acceptor_service<boost::asio::ip::tcp>::destro
y (this=0x4f2ae8c3, impl=@0x77c34e31)
    at D:/Dev-Cpp/include/boost/asio/socket_acceptor_service.hpp:109
109         service_impl_.destroy(impl);
(gdb) bt
#0  0x004b0a1c in boost::asio::socket_acceptor_service<boost::asio::ip::tcp>::de
stroy (this=0x4f2ae8c3, impl=@0x77c34e31)
    at D:/Dev-Cpp/include/boost/asio/socket_acceptor_service.hpp:109
#1  0x0040dd14 in Irc::Server::~Server (this=0x22ff30)
    at D:/Dev-Cpp/include/boost/asio/basic_io_object.hpp:84
#2  0x0041756d in main () at src/include/server.h:30
(gdb)

server.h:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#ifndef SERVER_H
#define SERVER_H

namespace Irc
{
	class Client;
	class Server;
} //namespace Irc

#include <boost/asio.hpp>
#include <map>

typedef boost::shared_ptr<Irc::Client> ClientPtr;
typedef boost::shared_ptr<boost::asio::ip::tcp::socket> SocketPtr;
typedef std::map<SocketPtr, ClientPtr> ClientsMap;

class Irc::Server
{
	public:
		Server();
		~Server();

		void start();

		void startAccept();

		void clientHandler(SocketPtr);

		ClientsMap::iterator begin() { return m_clients.begin(); }
		ClientsMap::iterator end() { return m_clients.end(); } // 30

	private:
		boost::asio::ip::tcp::acceptor* m_acceptor;
		boost::asio::io_service io;
		ClientsMap m_clients;
};
#endif 

server.cpp:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include "server.h"
#include "client.h"

#include <iostream>
#include <boost/thread.hpp>
#include <boost/bind.hpp>
#include <vector>
#include <boost/shared_ptr.hpp>

#include "defines.h"

Irc::Server::Server()
{
	//
}

Irc::Server::~Server()
{
	m_clients.clear();
	delete m_acceptor;
}

void Irc::Server::start()
{
	m_acceptor = new boost::asio::ip::tcp::acceptor(io);
}

void Irc::Server::startAccept()
{
	SocketPtr p(new boost::asio::ip::tcp::socket(io));
	boost::asio::ip::tcp::resolver resolver(io);
	boost::asio::ip::tcp::resolver::query query(SERVER_ADDRESS, SERVER_PORT);
	boost::asio::ip::tcp::endpoint endpoint = *resolver.resolve(query);
	m_acceptor->open(endpoint.protocol());
	m_acceptor->set_option(boost::asio::ip::tcp::acceptor::reuse_address(true));
	m_acceptor->bind(endpoint);
	m_acceptor->listen();
	m_acceptor->async_accept(*p,
		boost::bind(&Irc::Server::clientHandler, this, 
		p));
}

void Irc::Server::clientHandler(SocketPtr newSocket)
{
	typedef boost::shared_ptr<boost::thread> ThreadsPool;
	typedef std::vector<ThreadsPool> Threads;
	Threads threads;
	for (int i = 0; i < 2; ++i) {
		ThreadsPool p(new boost::thread(boost::bind(
			&boost::asio::io_service::run, &io)));
		threads.push_back(p);
	}
	for (Threads::iterator it = threads.begin(); it != threads.end(); ++it)
		(*it)->join();

	ClientPtr p(new Client(newSocket));
	m_clients[newSocket] = p;
	SocketPtr new_(new boost::asio::ip::tcp::socket(io));
	m_acceptor->async_accept(*new_,
		boost::bind(&Irc::Server::clientHandler, this, new_));
}

any help is apperciated.
Topic archived. No new replies allowed.