Author: rhuijben
Date: Thu Nov 19 13:07:24 2015
New Revision: 1715172
URL: http://svn.apache.org/viewvc?rev=1715172&view=rev
Log:
Improve logging code a bit, fixing some architecture issues with the help of
my VS2015 compiler's support via printf. Enable more help from gcc/clang.
* buckets/ssl_buckets.c
(apps_ssl_info_callback): Use last argument.
* incoming.c
(client_connected): Use %pp for pointers.
* outgoing.c
(clean_conn,
connect_connection,
serf__open_connections,
reset_connection,
read_from_connection,
serf_connection_create2,
serf_connection_close): Use %pp for pointers.
(serf_connection_set_async_responses): Set as bool.
* protocols/fcgi_protocol.c
(fcgi_process): Add missing argument.
* pump.c
(serf_pump__data_pending): Remove logging that doesn't make sense here.
(no_more_writes,
socket_writev,
serf_pump__write): Log pointer via %pp. Use generic value.
* serf_private.h
(includes): Add apr.h to ensure __attribute__ is defined.
(serf__log_nopref,
serf__log): Annotate with __attribute__.
Modified:
serf/trunk/buckets/ssl_buckets.c
serf/trunk/incoming.c
serf/trunk/outgoing.c
serf/trunk/protocols/fcgi_protocol.c
serf/trunk/pump.c
serf/trunk/serf_private.h
Modified: serf/trunk/buckets/ssl_buckets.c
URL:
http://svn.apache.org/viewvc/serf/trunk/buckets/ssl_buckets.c?rev=1715172&r1=1715171&r2=1715172&view=diff
==============================================================================
--- serf/trunk/buckets/ssl_buckets.c (original)
+++ serf/trunk/buckets/ssl_buckets.c Thu Nov 19 13:07:24 2015
@@ -177,7 +177,7 @@ struct serf_ssl_context_t {
const char *selected_protocol; /* Cached protocol value once available */
/* Protocol callback */
- serf_ssl_protocol_result_cb_t protocol_callback;
+ serf_ssl_protocol_result_cb_t protocol_callback;
void *protocol_userdata;
serf_config_t *config;
@@ -255,7 +255,7 @@ apps_ssl_info_callback(const SSL *s, int
if (ret > 0) {
/* ret > 0: Just a state change; not an error */
serf__log(level, LOGCOMP_SSL, __FILE__, ctx->config,
- "%s: %s\n",
+ "%s: %s (%d)\n",
str, SSL_state_string_long(s),
ctx->crypt_status);
}
@@ -282,7 +282,7 @@ apps_ssl_info_callback(const SSL *s, int
#endif
-/* Listens for the SSL renegotiate ciphers alert and report it back to the
+/* Listens for the SSL renegotiate ciphers alert and report it back to the
serf context. */
static void
detect_renegotiate(const SSL *s, int where, int ret)
@@ -647,7 +647,7 @@ get_subject_alt_names(apr_array_header_t
}
sk_GENERAL_NAME_pop_free(names, GENERAL_NAME_free);
}
-
+
return APR_SUCCESS;
}
@@ -698,7 +698,7 @@ validate_server_certificate(int cert_val
int err = X509_STORE_CTX_get_error(store_ctx);
switch(err) {
- case X509_V_ERR_CERT_NOT_YET_VALID:
+ case X509_V_ERR_CERT_NOT_YET_VALID:
failures |= SERF_SSL_CERT_NOTYETVALID;
break;
case X509_V_ERR_CERT_HAS_EXPIRED:
@@ -840,7 +840,7 @@ validate_server_certificate(int cert_val
{
ctx->pending_err = SERF_ERROR_SSL_CERT_FAILED;
}
-
+
return cert_valid;
}
@@ -1005,7 +1005,7 @@ static apr_status_t ssl_decrypt(void *ba
serf__log(LOGLVL_DEBUG, LOGCOMP_SSLMSG, __FILE__, ctx->config,
"---\n%.*s\n-(%d)-\n", *len, buf, *len);
}
-
+
if (!ctx->handshake_finished
&& !SERF_BUCKET_READ_ERROR(status)) {
@@ -1166,7 +1166,7 @@ static apr_status_t ssl_encrypt(void *ba
serf__log(LOGLVL_DEBUG, LOGCOMP_SSL, __FILE__, ctx->config,
"---\n%.*s\n-(%d)-\n",
interim_len, vecs_data, interim_len);
-
+
}
}
}
@@ -1352,10 +1352,10 @@ static void init_ssl_libraries(void)
thread has completed */
while (val != INIT_DONE) {
apr_sleep(APR_USEC_PER_SEC / 1000);
-
+
val = apr_atomic_cas32(&have_init_ssl,
INIT_UNINITIALIZED,
- INIT_UNINITIALIZED);
+ INIT_UNINITIALIZED);
}
}
}
@@ -2196,7 +2196,7 @@ const char *serf_ssl_cert_export(
encoded_cert = apr_palloc(pool, apr_base64_encode_len(len));
apr_base64_encode(encoded_cert, binary_cert, len);
-
+
return encoded_cert;
}
Modified: serf/trunk/incoming.c
URL:
http://svn.apache.org/viewvc/serf/trunk/incoming.c?rev=1715172&r1=1715171&r2=1715172&view=diff
==============================================================================
--- serf/trunk/incoming.c (original)
+++ serf/trunk/incoming.c Thu Nov 19 13:07:24 2015
@@ -38,7 +38,7 @@ static apr_status_t client_connected(ser
serf_pump__store_ipaddresses_in_config(&client->pump);
serf__log(LOGLVL_DEBUG, LOGCOMP_CONN, __FILE__, client->config,
- "socket for client 0x%x connected\n", client);
+ "socket for client 0x%pp connected\n", client);
/* ### Connection does auth setup here */
Modified: serf/trunk/outgoing.c
URL:
http://svn.apache.org/viewvc/serf/trunk/outgoing.c?rev=1715172&r1=1715171&r2=1715172&view=diff
==============================================================================
--- serf/trunk/outgoing.c (original)
+++ serf/trunk/outgoing.c Thu Nov 19 13:07:24 2015
@@ -61,7 +61,7 @@ static apr_status_t clean_conn(void *dat
serf_connection_t *conn = data;
serf__log(LOGLVL_DEBUG, LOGCOMP_CONN, __FILE__, conn->config,
- "cleaning up connection 0x%x\n", conn);
+ "cleaning up connection 0x%pp\n", conn);
serf_connection_close(conn);
return APR_SUCCESS;
@@ -336,7 +336,7 @@ static apr_status_t connect_connection(s
serf_pump__store_ipaddresses_in_config(&conn->pump);
serf__log(LOGLVL_DEBUG, LOGCOMP_CONN, __FILE__, conn->config,
- "socket for conn 0x%x connected\n", conn);
+ "socket for conn 0x%pp connected\n", conn);
/* If the authentication was already started on another connection,
prepare this connection (it might be possible to skip some
@@ -397,7 +397,7 @@ apr_status_t serf__open_connections(serf
#endif
conn->skt_pool);
serf__log(LOGLVL_DEBUG, LOGCOMP_CONN, __FILE__, conn->config,
- "created socket for conn 0x%x, status %d\n", conn, status);
+ "created socket for conn 0x%pp, status %d\n", conn, status);
if (status != APR_SUCCESS)
return status;
@@ -504,7 +504,7 @@ static apr_status_t reset_connection(ser
serf_request_t *old_reqs;
serf__log(LOGLVL_DEBUG, LOGCOMP_CONN, __FILE__, conn->config,
- "reset connection 0x%x\n", conn);
+ "reset connection 0x%pp\n", conn);
conn->probable_keepalive_limit = conn->completed_responses;
conn->completed_requests = 0;
@@ -1054,7 +1054,7 @@ error:
disable pipelining and reconnect to the server. */
serf__log(LOGLVL_WARNING, LOGCOMP_CONN, __FILE__, conn->config,
"The server requested renegotiation. Disable HTTP "
- "pipelining and reset the connection.\n", conn);
+ "pipelining and reset the connection 0x%pp.\n", conn);
serf__connection_set_pipelining(conn, 0);
reset_connection(conn, 1);
@@ -1363,7 +1363,7 @@ apr_status_t serf_connection_create2(
*conn = c;
serf__log(LOGLVL_DEBUG, LOGCOMP_CONN, __FILE__, c->config,
- "created connection 0x%x\n", c);
+ "created connection 0x%pp\n", c);
return status;
}
@@ -1429,7 +1429,7 @@ apr_status_t serf_connection_close(
--ctx->conns->nelts;
serf__log(LOGLVL_DEBUG, LOGCOMP_CONN, __FILE__, conn->config,
- "closed connection 0x%x\n", conn);
+ "closed connection 0x%pp\n", conn);
/* Found the connection. Closed it. All done. */
return APR_SUCCESS;
@@ -1490,7 +1490,7 @@ void serf_connection_set_framing_type(
if (conn->skt) {
serf_io__set_pollset_dirty(&conn->io);
- conn->pump.stop_writing = 0;
+ conn->pump.stop_writing = false;
conn->write_now = true;
/* Close down existing protocol */
Modified: serf/trunk/protocols/fcgi_protocol.c
URL:
http://svn.apache.org/viewvc/serf/trunk/protocols/fcgi_protocol.c?rev=1715172&r1=1715171&r2=1715172&view=diff
==============================================================================
--- serf/trunk/protocols/fcgi_protocol.c (original)
+++ serf/trunk/protocols/fcgi_protocol.c Thu Nov 19 13:07:24 2015
@@ -214,7 +214,7 @@ static apr_status_t fcgi_process(serf_fc
SERF_FCGI_assert(fcgi->read_frame != NULL);
}
- serf__log(LOGLVL_INFO, SERF_LOGFCGI, fcgi->config,
+ serf__log(LOGLVL_INFO, SERF_LOGFCGI, __FILE__, fcgi->config,
"Reading 0x%x frame, stream=0x%x\n",
frametype, sid);
Modified: serf/trunk/pump.c
URL:
http://svn.apache.org/viewvc/serf/trunk/pump.c?rev=1715172&r1=1715171&r2=1715172&view=diff
==============================================================================
--- serf/trunk/pump.c (original)
+++ serf/trunk/pump.c Thu Nov 19 13:07:24 2015
@@ -104,9 +104,6 @@ bool serf_pump__data_pending(serf_pump_t
status = serf_bucket_peek(pump->ostream_head, &data, &len);
if (!SERF_BUCKET_READ_ERROR(status)) {
if (len > 0) {
- serf__log(LOGLVL_DEBUG, LOGCOMP_CONN, __FILE__, pump->config,
- "Extra data to be written after sending complete "
- "requests.\n");
return true;
}
}
@@ -205,7 +202,7 @@ static apr_status_t no_more_writes(serf_
/* Note that we should hold new requests until we open our new socket. */
pump->done_writing = true;
serf__log(LOGLVL_DEBUG, LOGCOMP_CONN, __FILE__, pump->config,
- "stop writing on 0x%x\n", pump->io->u.conn);
+ "stop writing on 0x%pp\n", pump->io->u.v);
/* Clear our iovec. */
pump->vec_len = 0;
@@ -227,7 +224,7 @@ static apr_status_t socket_writev(serf_p
pump->vec_len, &written);
if (status && !APR_STATUS_IS_EAGAIN(status))
serf__log(LOGLVL_DEBUG, LOGCOMP_CONN, __FILE__, pump->config,
- "socket_sendv error %d\n", status);
+ "socket_sendv error %d on 0x%pp\n", status, pump->io->u.v);
/* did we write everything? */
if (written) {
@@ -235,7 +232,8 @@ static apr_status_t socket_writev(serf_p
int i;
serf__log(LOGLVL_DEBUG, LOGCOMP_CONN, __FILE__, conn->config,
- "--- socket_sendv: %d bytes. --\n", written);
+ "--- socket_sendv: %d bytes on 0x%pp. --\n",
+ written, pump->io->u.v);
for (i = 0; i < conn->vec_len; i++) {
len += conn->vec[i].iov_len;
@@ -330,6 +328,11 @@ apr_status_t serf_pump__write(serf_pump_
we can actually write something. otherwise, we could
end up in a CPU spin: socket wants something, but we
don't have anything (and keep returning EAGAIN) */
+
+ serf__log(LOGLVL_INFO, LOGCOMP_CONN, __FILE__, pump->config,
+ "Output stream requested temporary write delay "
+ "on 0x%pp\n", pump->io->u.v);
+
pump->stop_writing = true;
serf_io__set_pollset_dirty(pump->io);
Modified: serf/trunk/serf_private.h
URL:
http://svn.apache.org/viewvc/serf/trunk/serf_private.h?rev=1715172&r1=1715171&r2=1715172&view=diff
==============================================================================
--- serf/trunk/serf_private.h (original)
+++ serf/trunk/serf_private.h Thu Nov 19 13:07:24 2015
@@ -43,6 +43,8 @@ typedef int serf__bool_t; /* Not _Bool *
#endif
#endif
+#include <apr.h> /* For __attribute__ */
+
/* Define a MAX macro if we don't already have one */
#ifndef MAX
#define MAX(a, b) ((a) < (b) ? (b) : (a))
@@ -136,6 +138,7 @@ typedef struct serf_io_baton_t {
serf_incoming_t *client;
serf_connection_t *conn;
serf_listener_t *listener;
+ const void *const v;
} u;
/* are we a dirty connection that needs its poll status updated? */
@@ -782,11 +785,13 @@ apr_status_t serf__log_init(serf_context
/* Logs a standard event, but without prefix. This is useful to build up
log lines in parts. */
void serf__log_nopref(apr_uint32_t level, apr_uint32_t comp,
- serf_config_t *config, const char *fmt, ...);
+ serf_config_t *config, const char *fmt, ...)
+ __attribute__((format(printf, 4, 5)));
/* Logs an event, uses CONFIG to find out socket related info. */
void serf__log(apr_uint32_t level, apr_uint32_t comp, const char *filename,
- serf_config_t *config, const char *fmt, ...);
+ serf_config_t *config, const char *fmt, ...)
+ __attribute__((format(printf, 5, 6)));
/* Returns non-zero if logging is enabled for provided LEVEL/COMP.
* This function can be useful in cases if logging information if somewhat