/* * Curl_write() is an internal write function that sends data to the * server. Works with plain sockets, SCP, SSL or kerberos. */ CURLcode Curl_write(struct connectdata *conn, curl_socket_t sockfd, const void *mem, size_t len, ssize_t *written) { ssize_t bytes_written; CURLcode retcode; int num = (sockfd == conn->sock[SECONDARYSOCKET]); if(conn->ssl[num].state == ssl_connection_complete) /* only TRUE if SSL enabled */ bytes_written = Curl_ssl_send(conn, num, mem, len); #ifdef USE_LIBSSH2 else if(conn->protocol & PROT_SCP) bytes_written = Curl_scp_send(conn, num, mem, len); else if(conn->protocol & PROT_SFTP) bytes_written = Curl_sftp_send(conn, num, mem, len); #endif /* !USE_LIBSSH2 */ else if(conn->sec_complete) /* only TRUE if krb enabled */ bytes_written = Curl_sec_send(conn, num, mem, len); else bytes_written = send_plain(conn, num, mem, len); *written = bytes_written; retcode = (-1 != bytes_written)?CURLE_OK:CURLE_SEND_ERROR; return retcode; }
/* * Curl_write() is an internal write function that sends data to the * server. Works with plain sockets, SCP, SSL or kerberos. */ CURLcode Curl_write(struct connectdata *conn, curl_socket_t sockfd, const void *mem, size_t len, ssize_t *written) { ssize_t bytes_written; CURLcode retcode; int num = (sockfd == conn->sock[SECONDARYSOCKET]); if(conn->ssl[num].state == ssl_connection_complete) bytes_written = Curl_ssl_send(conn, num, mem, len); else if(Curl_ssh_enabled(conn, PROT_SCP)) bytes_written = Curl_scp_send(conn, num, mem, len); else if(Curl_ssh_enabled(conn, PROT_SFTP)) bytes_written = Curl_sftp_send(conn, num, mem, len); else if(conn->sec_complete) bytes_written = Curl_sec_send(conn, num, mem, len); else bytes_written = send_plain(conn, num, mem, len); *written = bytes_written; retcode = (-1 != bytes_written)?CURLE_OK:CURLE_SEND_ERROR; return retcode; }
/* * Curl_write_plain() is an internal write function that sends data to the * server using plain sockets only. Otherwise meant to have the exact same * proto as Curl_write() */ CURLcode Curl_write_plain(struct connectdata *conn, curl_socket_t sockfd, const void *mem, size_t len, ssize_t *written) { ssize_t bytes_written; CURLcode retcode; int num = (sockfd == conn->sock[SECONDARYSOCKET]); bytes_written = send_plain(conn, num, mem, len); *written = bytes_written; retcode = (-1 != bytes_written)?CURLE_OK:CURLE_SEND_ERROR; return retcode; }
/* * Curl_write() is an internal write function that sends data to the * server. Works with plain sockets, SCP, SSL or kerberos. * * If the write would block (EWOULDBLOCK), we return CURLE_OK and * (*written == 0). Otherwise we return regular CURLcode value. */ CURLcode Curl_write(struct connectdata *conn, curl_socket_t sockfd, const void *mem, size_t len, ssize_t *written) { ssize_t bytes_written; int curlcode = CURLE_OK; int num = (sockfd == conn->sock[SECONDARYSOCKET]); if(conn->ssl[num].state == ssl_connection_complete) bytes_written = Curl_ssl_send(conn, num, mem, len, &curlcode); else if(Curl_ssh_enabled(conn, PROT_SCP)) bytes_written = Curl_scp_send(conn, num, mem, len); else if(Curl_ssh_enabled(conn, PROT_SFTP)) bytes_written = Curl_sftp_send(conn, num, mem, len); else if(conn->sec_complete) bytes_written = Curl_sec_send(conn, num, mem, len); else bytes_written = send_plain(conn, num, mem, len); *written = bytes_written; if(-1 != bytes_written) /* we completely ignore the curlcode value when -1 is not returned */ return CURLE_OK; /* handle EWOULDBLOCK or a send failure */ switch(curlcode) { case /* EWOULDBLOCK */ -1: *written = /* EWOULDBLOCK */ 0; return CURLE_OK; case CURLE_OK: /* general send failure */ return CURLE_SEND_ERROR; default: /* we got a specific curlcode, forward it */ return (CURLcode)curlcode; } }
gpointer active_thread_func(gpointer user_data) { ThreadData *thread_context = (ThreadData *)user_data; PluginOption *option = thread_context->option; int sock_type = SOCK_STREAM; if (sock_type_d) sock_type = SOCK_DGRAM; if (sock_type_s) sock_type = SOCK_STREAM; char *message = g_malloc0(MAX_MESSAGE_LENGTH+1); int fd; if (unix_socket_x) fd = connect_unix_domain_socket(sock_type, option->target); else fd = connect_ip_socket(sock_type, option->target, option->port, option->use_ipv6); if (fd<0) { ERROR("can not connect to %s:%s (%p)\n",option->target, option->port,g_thread_self()); } else { DEBUG("(%d) connected to server on socket %d (%p)\n",thread_context->index,fd,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 (fd>0 && 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 = send_plain(fd, message + sent, strlen(message) - sent); if (rc < 0) { ERROR("error sending buffer on %d (rc=%zd)\n",fd,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_free((gpointer)message); g_mutex_lock(thread_lock); active_thread_count--; g_mutex_unlock(thread_lock); close(fd); g_thread_exit(NULL); return NULL; }