Пример #1
0
gpointer
idle_thread_func(gpointer user_data)
{
  PluginOption *option = ((ThreadData *)user_data)->option;
  int thread_index = ((ThreadData *)user_data)->index;
  int sock_fd = connect_ip_socket(SOCK_STREAM, option->target, option->port, option->use_ipv6);;

  SSL *ssl = open_ssl_connection(sock_fd);
  if (ssl == NULL)
    {
      ERROR("can not connect to %s:%s (%p)\n",option->target, option->port,g_thread_self());
    }
  else
    {
      DEBUG("(%d) connected to server on socket (%p)\n",thread_index,g_thread_self());
    }

  g_mutex_lock(thread_lock);
  connect_finished++;

  if (connect_finished == active_thread_count + idle_thread_count)
    g_cond_broadcast(thread_connected);

  g_mutex_unlock(thread_lock);

  DEBUG("thread (%s,%p) created. wait for start ...\n",loggen_plugin_info.name,g_thread_self());
  g_mutex_lock(thread_lock);
  while (!thread_run)
    {
      g_cond_wait(thread_start,thread_lock);
    }
  g_mutex_unlock(thread_lock);

  DEBUG("thread (%s,%p) started. (r=%d,c=%d)\n",loggen_plugin_info.name,g_thread_self(),option->rate,
        option->number_of_messages);

  while (thread_run && active_thread_count>0)
    {
      g_usleep(10*1000);
    }

  g_mutex_lock(thread_lock);
  idle_thread_count--;
  g_mutex_unlock(thread_lock);

  close_ssl_connection(ssl);
  close(sock_fd);
  g_thread_exit(NULL);
  return NULL;
}
Пример #2
0
static rfbBool
InitializeTLSSession(rfbClient* client, rfbBool anonTLS)
{
  int ret;

  if (client->tlsSession) return TRUE;

  client->tlsSession = open_ssl_connection (client, client->sock, anonTLS);

  if (!client->tlsSession)
    return FALSE;

  rfbClientLog("TLS session initialized.\n");

  return TRUE;
}
Пример #3
0
gpointer
active_thread_func(gpointer user_data)
{
  ThreadData *thread_context = (ThreadData *)user_data;
  PluginOption *option = thread_context->option;

  char *message = g_malloc0(MAX_MESSAGE_LENGTH+1);
  int sock_fd = connect_ip_socket(SOCK_STREAM, option->target, option->port, option->use_ipv6);;

  SSL *ssl = open_ssl_connection(sock_fd);

  if (ssl == NULL)
    {
      ERROR("can not connect to %s:%s (%p)\n",option->target, option->port,g_thread_self());
    }
  else
    {
      DEBUG("(%d) connected to server on socket (%p)\n",thread_context->index,g_thread_self());
    }

  g_mutex_lock(thread_lock);
  connect_finished++;

  if (connect_finished == active_thread_count + idle_thread_count)
    g_cond_broadcast(thread_connected);

  g_mutex_unlock(thread_lock);

  DEBUG("thread (%s,%p) created. wait for start ...\n",loggen_plugin_info.name,g_thread_self());
  g_mutex_lock(thread_lock);
  while (!thread_run)
    {
      g_cond_wait(thread_start,thread_lock);
    }
  g_mutex_unlock(thread_lock);

  DEBUG("thread (%s,%p) started. (r=%d,c=%d)\n",loggen_plugin_info.name,g_thread_self(),option->rate,
        option->number_of_messages);

  unsigned long count = 0;
  thread_context->buckets = thread_context->option->rate - (thread_context->option->rate / 10);

  gettimeofday(&thread_context->last_throttle_check, NULL);
  gettimeofday(&thread_context->start_time, NULL);

  gboolean connection_error = FALSE;

  while (ssl && thread_run && !connection_error)
    {
      if (thread_check_exit_criteria(thread_context))
        break;

      if (thread_check_time_bucket(thread_context))
        continue;

      if (!generate_message)
        {
          ERROR("generate_message not yet set up(%p)\n",g_thread_self());
          break;
        }

      int str_len = generate_message(message, MAX_MESSAGE_LENGTH, thread_context->index, count++);

      if (str_len < 0)
        {
          ERROR("can't generate more log lines. end of input file?\n");
          break;
        }

      ssize_t sent = 0;
      while (sent < strlen(message))
        {
          ssize_t rc = SSL_write(ssl, message + sent, strlen(message) - sent);
          if (rc < 0)
            {
              ERROR("error sending buffer on %p (rc=%zd)\n",ssl,rc);
              errno = ECONNABORTED;
              connection_error = TRUE;
              break;
            }
          sent += rc;
        }

      thread_context->sent_messages++;
      thread_context->buckets--;
    }
  DEBUG("thread (%s,%p) finished\n",loggen_plugin_info.name,g_thread_self());

  g_mutex_lock(thread_lock);
  active_thread_count--;
  g_mutex_unlock(thread_lock);

  g_free((gpointer)message);
  close_ssl_connection(ssl);
  close(sock_fd);

  g_thread_exit(NULL);
  return NULL;
}