File: socketmanager.h

package info (click to toggle)
dc-qt 0.2.0.alpha-4
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 1,948 kB
  • ctags: 5,361
  • sloc: cpp: 28,936; makefile: 19
file content (57 lines) | stat: -rw-r--r-- 1,060 bytes parent folder | download | duplicates (4)
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
#ifndef RPCSOCKETMANAGER_H
#define RPCSOCKETMANAGER_H

#include <set>

#include "socket.h"

namespace rpc {

/**
	@author Rikard Bjorklind <olof@linux.nu>
*/
class SocketManager{
public:
    ~SocketManager();

	/**
	 * Add the socket to our internal set.
	 */
	void addSocket(Socket*);
	
	/**
	 * Remove the specified socket from our internal set.
	 */
	void removeSocket(Socket*);

	/**
	 * Perform a select on all the sockets that we are managing. This call
	 * blocks until something is available to read.
	 */
	void select();

	static SocketManager* instance() {if(!inst) inst=new SocketManager;return inst;}

	const std::set<Socket*>& getSockets() const { return sockets; }
	
	Socket* findSocket( int socketId );
	
private:
	/**
	 * Singleton has private ctor so that it can only be accessed by
	 * the instance method.
	 */
	SocketManager();
	
	/// One and only instance of the socketmanager
	static SocketManager* inst;
	
	/// The sockets that we are managing
	std::set<Socket*> sockets;
};

}

#define g_SocketManager SocketManager::instance()

#endif