Exemple #1
0
// Lua: res, err = send( sock, str )
static int net_send( lua_State *L )
{
	int sock = ( int )luaL_checkinteger( L, 1 );
	const char *buf;
	size_t len;

	luaL_checktype( L, 2, LUA_TSTRING );
	buf = lua_tolstring( L, 2, &len );
	lua_pushinteger( L, elua_net_send( sock, buf, len ) );
	lua_pushinteger( L, elua_net_get_last_err( sock ) );
	return 2;
}
Exemple #2
0
// 'write'
static _ssize_t std_write( struct _reent *r, int fd, const void* vptr, size_t len, void *pdata )
{   
  int sock;
  
  // Check file number
  if( ( fd != DM_STDOUT_NUM ) && ( fd != DM_STDERR_NUM ) )
  {
    r->_errno = EINVAL;
    return -1;
  }  
  
  // Get (and wait for) socket
  while( ( sock = elua_net_get_telnet_socket() ) == - 1 );  
  
  // Send data
  elua_net_send( sock, vptr, len );
  return len;
}