Back to index

texmacs  1.0.7.15
Functions | Variables
socket_link.cpp File Reference
#include "socket_link.hpp"
#include "sys_utils.hpp"
#include "hashset.hpp"
#include "iterator.hpp"
#include "timer.hpp"
#include "scheme.hpp"
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/wait.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
#include <errno.h>

Go to the source code of this file.

Functions

void socket_callback (void *obj, void *info)
tm_link make_socket_link (string host, int port, int type, int fd)
tm_link find_socket_link (int fd)
void close_all_sockets ()
static string debug_io_string (string s)
static int send_all (int s, char *buf, int *len)

Variables

hashset< pointersocket_link_set

Function Documentation

Definition at line 71 of file socket_link.cpp.

                     {
#ifndef __MINGW32__
  iterator<pointer> it= iterate (socket_link_set);
  while (it->busy()) {
    socket_link_rep* con= (socket_link_rep*) it->next();
    if (con->alive) {
      // FIXME: cleanly close the connection to the socket here
      con->alive= false;
    }
  }
#endif
}

Here is the call graph for this function:

static string debug_io_string ( string  s) [static]

Definition at line 128 of file socket_link.cpp.

                           {
  int i, n= N(s);
  string r;
  for (i=0; i<n; i++) {
    unsigned char c= (unsigned char) s[i];
    if (c == DATA_BEGIN) r << "[BEGIN]";
    else if (c == DATA_END) r << "[END]";
    else if (c == DATA_COMMAND) r << "[COMMAND]";
    else if (c == DATA_ESCAPE) r << "[ESCAPE]";
    else r << s[i];
  }
  return r;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 61 of file socket_link.cpp.

                          {
  iterator<pointer> it= iterate (socket_link_set);
  while (it->busy()) {
    socket_link_rep* con= (socket_link_rep*) it->next();
    if (con->io == fd && con->alive) return tm_link (con);
  }
  return tm_link ();
}

Here is the call graph for this function:

Here is the caller graph for this function:

tm_link make_socket_link ( string  host,
int  port,
int  type,
int  fd 
)

Definition at line 56 of file socket_link.cpp.

                                                           {
  return tm_new<socket_link_rep> (host, port, type, fd);
}

Here is the caller graph for this function:

static int send_all ( int  s,
char *  buf,
int *  len 
) [static]

Definition at line 143 of file socket_link.cpp.

                                      {
#ifndef __MINGW32__
  int total= 0;          // how many bytes we've sent
  int bytes_left= *len;  // how many we have left to send
  int n= 0;

  while (total < *len) {
    n= send (s, buf + total, bytes_left, 0);
    if (n == -1) break;
    total += n;
    bytes_left -= n;
  }

  *len= total;
  return n==-1? -1: 0;
#else
  return 0;
#endif
} 

Here is the call graph for this function:

Here is the caller graph for this function:

void socket_callback ( void *  obj,
void *  info 
)

Definition at line 248 of file socket_link.cpp.

                                        {
#ifndef __MINGW32__
  (void) info;
  socket_link_rep* con= (socket_link_rep*) obj;  
  bool busy= true;
  bool news= false;
  while (busy) {
    fd_set rfds;
    FD_ZERO (&rfds);
    int max_fd= con->io + 1;
    FD_SET (con->io, &rfds);
  
    struct timeval tv;
    tv.tv_sec  = 0;
    tv.tv_usec = 0;
    select (max_fd, &rfds, NULL, NULL, &tv);

    busy= false;
    if (con->alive && FD_ISSET (con->io, &rfds)) {
      //cout << "socket_callback OUT" << LF;
      con->feed (LINK_OUT);
      busy= news= true;
    }
  }
  if (!is_nil (con->feed_cmd) && news)
    con->feed_cmd->apply ();
#endif
}

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

Definition at line 32 of file socket_link.cpp.