socket_io.h File Reference

#include <ndb_global.h>
#include <NdbTCP.h>

Go to the source code of this file.

Functions

int print_socket (NDB_SOCKET_TYPE, int timeout_ms, const char *,...)
int println_socket (NDB_SOCKET_TYPE, int timeout_ms, const char *,...)
int read_socket (NDB_SOCKET_TYPE, int timeout_ms, char *, int len)
int readln_socket (NDB_SOCKET_TYPE, int timeout_ms, char *, int len)
int vprint_socket (NDB_SOCKET_TYPE, int timeout_ms, const char *, va_list)
int vprintln_socket (NDB_SOCKET_TYPE, int timeout_ms, const char *, va_list)
int write_socket (NDB_SOCKET_TYPE, int timeout_ms, const char[], int len)


Function Documentation

int print_socket NDB_SOCKET_TYPE  ,
int  timeout_ms,
const char *  ,
  ...
 

Definition at line 148 of file socket_io.cpp.

References vprint_socket().

00149                                    {
00150   va_list ap;
00151   va_start(ap, fmt);
00152   int ret = vprint_socket(socket, timeout_millis, fmt, ap);
00153   va_end(ap);
00154 
00155   return ret;
00156 }

int println_socket NDB_SOCKET_TYPE  ,
int  timeout_ms,
const char *  ,
  ...
 

Definition at line 160 of file socket_io.cpp.

References vprintln_socket().

Referenced by Ndb_mgmd_event_service::log().

00161                                      {
00162   va_list ap;
00163   va_start(ap, fmt);
00164   int ret = vprintln_socket(socket, timeout_millis, fmt, ap);
00165   va_end(ap);
00166   return ret;
00167 }

int read_socket NDB_SOCKET_TYPE  ,
int  timeout_ms,
char *  ,
int  len
 

Definition at line 25 of file socket_io.cpp.

Referenced by ndb_mgm_get_configuration().

00026                                    {
00027   if(buflen < 1)
00028     return 0;
00029   
00030   fd_set readset;
00031   FD_ZERO(&readset);
00032   FD_SET(socket, &readset);
00033   
00034   struct timeval timeout;
00035   timeout.tv_sec  = (timeout_millis / 1000);
00036   timeout.tv_usec = (timeout_millis % 1000) * 1000;
00037 
00038   const int selectRes = select(socket + 1, &readset, 0, 0, &timeout);
00039   if(selectRes == 0)
00040     return 0;
00041   
00042   if(selectRes == -1){
00043     return -1;
00044   }
00045 
00046   return recv(socket, &buf[0], buflen, 0);
00047 }

int readln_socket NDB_SOCKET_TYPE  ,
int  timeout_ms,
char *  ,
int  len
 

Definition at line 51 of file socket_io.cpp.

References pos().

Referenced by SocketInputStream::gets().

00052                                      {
00053   if(buflen <= 1)
00054     return 0;
00055 
00056   fd_set readset;
00057   FD_ZERO(&readset);
00058   FD_SET(socket, &readset);
00059   
00060   struct timeval timeout;
00061   timeout.tv_sec  = (timeout_millis / 1000);
00062   timeout.tv_usec = (timeout_millis % 1000) * 1000;
00063 
00064   const int selectRes = select(socket + 1, &readset, 0, 0, &timeout);
00065   if(selectRes == 0)
00066     return 0;
00067   
00068   if(selectRes == -1){
00069     return -1;
00070   }
00071   
00072   int pos = 0; buf[pos] = 0;
00073   while(true){
00074     const int t = recv(socket, &buf[pos], 1, 0);
00075     if(t != 1){
00076       return -1;
00077     }
00078     if(buf[pos] == '\n'){
00079       buf[pos] = 0;
00080 
00081       if(pos > 0 && buf[pos-1] == '\r'){
00082         pos--;
00083         buf[pos] = 0;
00084       }
00085 
00086       return pos;
00087     }
00088     pos++;
00089     if(pos == (buflen - 1)){
00090       buf[pos] = 0;
00091       return buflen;
00092     }
00093     
00094     FD_ZERO(&readset);
00095     FD_SET(socket, &readset);
00096     timeout.tv_sec  = (timeout_millis / 1000);
00097     timeout.tv_usec = (timeout_millis % 1000) * 1000;
00098     const int selectRes = select(socket + 1, &readset, 0, 0, &timeout);
00099     if(selectRes != 1){
00100       return -1;
00101     }
00102   }
00103 }

int vprint_socket NDB_SOCKET_TYPE  ,
int  timeout_ms,
const char *  ,
va_list 
 

Definition at line 171 of file socket_io.cpp.

References buf, free, malloc, NULL, size, BaseString::vsnprintf(), and write_socket().

Referenced by SocketOutputStream::print(), and print_socket().

00172                                            {
00173   char buf[1000];
00174   char *buf2 = buf;
00175   size_t size;
00176 
00177   if (fmt != 0 && fmt[0] != 0) {
00178     size = BaseString::vsnprintf(buf, sizeof(buf), fmt, ap);
00179     /* Check if the output was truncated */
00180     if(size > sizeof(buf)) {
00181       buf2 = (char *)malloc(size);
00182       if(buf2 == NULL)
00183         return -1;
00184       BaseString::vsnprintf(buf2, size, fmt, ap);
00185     }
00186   } else
00187     return 0;
00188 
00189   int ret = write_socket(socket, timeout_millis, buf2, size);
00190   if(buf2 != buf)
00191     free(buf2);
00192   return ret;
00193 }

int vprintln_socket NDB_SOCKET_TYPE  ,
int  timeout_ms,
const char *  ,
va_list 
 

Definition at line 197 of file socket_io.cpp.

References buf, free, malloc, NULL, size, BaseString::vsnprintf(), and write_socket().

Referenced by SocketOutputStream::println(), and println_socket().

00198                                              {
00199   char buf[1000];
00200   char *buf2 = buf;
00201   size_t size;
00202 
00203   if (fmt != 0 && fmt[0] != 0) {
00204     size = BaseString::vsnprintf(buf, sizeof(buf), fmt, ap)+1;// extra byte for '/n'
00205     /* Check if the output was truncated */
00206     if(size > sizeof(buf)) {
00207       buf2 = (char *)malloc(size);
00208       if(buf2 == NULL)
00209         return -1;
00210       BaseString::vsnprintf(buf2, size, fmt, ap);
00211     }
00212   } else {
00213     size = 1;
00214   }
00215   buf2[size-1]='\n';
00216 
00217   int ret = write_socket(socket, timeout_millis, buf2, size);
00218   if(buf2 != buf)
00219     free(buf2);
00220   return ret;
00221 }

int write_socket NDB_SOCKET_TYPE  ,
int  timeout_ms,
const   char[],
int  len
 

Referenced by MgmApiSession::getConfig_common(), vprint_socket(), and vprintln_socket().


Generated on Wed Jul 20 21:09:35 2005 for MySQL 5.0.9 Beta by  doxygen 1.4.3