14
14
#include "socket_link.hpp"
15
15
#include "scheme.hpp"
17
static socket_link_rep* the_client= NULL;
17
typedef socket_link_rep* weak_socket_link;
18
static array<weak_socket_link> the_clients;
19
static bool clients_started= false;
19
21
/******************************************************************************
21
23
******************************************************************************/
24
26
client_start (string host) {
25
if (the_client == NULL) {
27
if (!clients_started) {
26
28
(void) eval ("(use-modules (remote texmacs-client))");
27
the_client= tm_new<socket_link_rep> (host, 6561, SOCKET_CLIENT, -1);
29
if (!the_client->alive)
30
cout << "TeXmacs] Starting client... " << the_client->start () << "\n";
29
clients_started= true;
31
weak_socket_link client=
32
tm_new<socket_link_rep> (host, 6561, SOCKET_CLIENT, -1);
34
cout << "TeXmacs] Starting client... " << client->start () << "\n";
36
call ("client-add", object (client->io));
37
the_clients << client;
35
if (the_client != NULL) {
37
tm_delete (the_client);
44
client_stop (int fd) {
45
for (int i=0; i<N(the_clients); i++)
46
if (the_clients[i]->io == fd) {
47
weak_socket_link client= the_clients[i];
51
the_clients= append (range (the_clients, 0, i),
52
range (the_clients, i+1, N(the_clients)));
56
static weak_socket_link
57
find_client (int fd) {
58
for (int i=0; i<N(the_clients); i++)
59
if (the_clients[i]->io == fd)
60
return the_clients[i];
44
if (the_client == NULL || !the_client->alive) return "";
45
if (!the_client->complete_packet (LINK_OUT)) return "";
65
client_read (int fd) {
66
weak_socket_link client= find_client (fd);
67
if (client == NULL || !client->alive) return "";
68
if (!client->complete_packet (LINK_OUT)) return "";
47
string back= the_client->read_packet (LINK_OUT, 0, success);
70
string back= client->read_packet (LINK_OUT, 0, success);
48
71
//cout << "Server read " << back << "\n";
53
client_write (string s) {
54
if (the_client == NULL || !the_client->alive) return;
76
client_write (int fd, string s) {
77
weak_socket_link client= find_client (fd);
78
if (client == NULL || !client->alive) return;
55
79
//cout << "Client write " << s << "\n";
56
the_client->write_packet (s, LINK_IN);
80
client->write_packet (s, LINK_IN);
60
enter_secure_mode () {
61
the_client->secure_client ();
84
enter_secure_mode (int fd) {
85
weak_socket_link client= find_client (fd);
86
if (client == NULL || !client->alive) return;
87
client->secure_client ();