4 * This file is part of LyX, the document processor.
5 * Licence details can be found in the file COPYING.
7 * \author Lars Gullik Bjønnes
8 * \author Jean-Marc Lasgouttes
9 * \author João Luis M. Assirati
11 * Full author contact details are available in file CREDITS.
14 #ifndef LYXSERVERSOCKET_H
15 #define LYXSERVERSOCKET_H
17 #include "support/FileName.h"
18 #include "support/socktools.h"
20 #include <boost/shared_ptr.hpp>
31 /** Sockets can be in two states: listening and connected.
32 * Connected sockets are used to transfer data, and will therefore
33 * be called Data Sockets. Listening sockets are used to create
34 * Data Sockets when clients connect, and therefore will be called
37 * This class encapsulates local (unix) server socket operations and
38 * manages LyXDataSockets objects that are created when clients connect.
43 ServerSocket(support::FileName const &);
46 /// Address of the local socket
47 std::string const address() const;
48 /// To be called when there is activity in the server socket
49 void serverCallback();
50 /// To be called when there is activity in the data socket
51 void dataCallback(int fd);
54 void writeln(std::string const &);
55 /// File descriptor for the server socket
57 /// Stores the socket filename
58 support::FileName address_;
59 /// Maximum number of simultaneous clients
64 std::map<int, boost::shared_ptr<LyXDataSocket> > clients;
68 /** This class encapsulates data socket operations.
69 * It provides read and write IO operations on the socket.
74 LyXDataSocket(int fd);
78 bool connected() const;
79 /// Line buffered input from the socket
80 bool readln(std::string &);
81 /// Write the string + '\n' to the socket
82 void writeln(std::string const &);
84 /// File descriptor for the data socket
86 /// True if the connection is up
88 /// buffer for input data
92 /// Implementation is in LyX.cpp
93 extern ServerSocket & theServerSocket();
98 #endif // LYXSERVERSOCKET_H