-
-
Save luhenry/9692303 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/mono/utils/mono-counters-agent.c b/mono/utils/mono-counters-agent.c | |
index a235c0a..d62d192 100644 | |
--- a/mono/utils/mono-counters-agent.c | |
+++ b/mono/utils/mono-counters-agent.c | |
@@ -40,7 +40,7 @@ enum { | |
SRV_REMOTE_COUNTER, | |
SVR_SAMPLES, | |
}; | |
- | |
+ | |
/** | |
* Protocol : | |
* | Headers | Values | Values | ... [Infinity] | |
@@ -164,7 +164,7 @@ static gboolean | |
write_buffer_to_socket (int fd, const char* buffer, size_t size) | |
{ | |
size_t sent = 0; | |
- | |
+ | |
while (sent < size) { | |
ssize_t res = send (fd, buffer + sent, size - sent, 0); | |
if (res <= 0) | |
@@ -193,6 +193,9 @@ read_socket_to_buffer (int fd, char* buffer, size_t size) | |
static gboolean | |
write_counter_agent_header (int socketfd, MonoCounterAgent *counter_agent) | |
{ | |
+ if (!counter_agent->counter) | |
+ return FALSE; | |
+ | |
int len = strlen (counter_agent->counter->name); | |
if (!write_buffer_to_socket(socketfd, (char*)&counter_agent->counter->category, 4) || | |
@@ -287,7 +290,7 @@ do_add_counter (int socketfd) | |
if (!(name = read_string (socketfd))) | |
goto fail; | |
- | |
+ | |
counter = mono_counters_get (category, name); | |
if (counter) { | |
status = AGENT_STATUS_EXISTING; | |
@@ -414,55 +417,34 @@ do_sampling (int socketfd) | |
static void* | |
mono_counters_agent_sampling_thread (void* ptr) | |
{ | |
- GSList *item; | |
int ret, socketfd = -1; | |
- short count = 0; | |
struct sockaddr_in inspector_addr; | |
struct timeval timeout; | |
fd_set socketfd_set; | |
gint64 last_sampling = 0, now; | |
char cmd; | |
- | |
+ | |
if ((socketfd = socket (AF_INET, SOCK_STREAM, 0)) < 0) { | |
g_warning ("mono-counters-agent: error with socket : %s", strerror (errno)); | |
return NULL; | |
} | |
- | |
+ | |
memset (&inspector_addr, 0, sizeof (inspector_addr)); | |
- | |
+ | |
inspector_addr.sin_family = AF_INET; | |
inspector_addr.sin_port = htons (inspector_port); | |
- | |
+ | |
if (!inet_pton (AF_INET, inspector_ip, &inspector_addr.sin_addr)) { | |
g_warning ("mono-counters-agent: error with inet_pton : %s", strerror (errno)); | |
goto cleanup; | |
} | |
- | |
+ | |
if (connect(socketfd, (struct sockaddr*)&inspector_addr, sizeof(inspector_addr)) < 0) { | |
g_warning ("mono-counters-agent: error with connect : %s", strerror(errno)); | |
goto cleanup; | |
} | |
- for (item = counters; item; item = item->next) | |
- ++count; | |
- | |
- if (!write_buffer_to_socket (socketfd, (char*)&count, 2)) | |
- goto cleanup; | |
- | |
- for (item = counters; item; item = item->next) { | |
- MonoCounterAgent* counter = item->data; | |
- | |
- int len = strlen (counter->counter->name); | |
- | |
- if (!write_buffer_to_socket(socketfd, (char*)&counter->counter->category, 4) || | |
- !write_buffer_to_socket (socketfd, (char*)&len, 4) || | |
- !write_buffer_to_socket (socketfd, (char*)counter->counter->name, len) || | |
- !write_buffer_to_socket (socketfd, (char*)&counter->counter->type, 4) || | |
- !write_buffer_to_socket (socketfd, (char*)&counter->counter->unit, 4) || | |
- !write_buffer_to_socket (socketfd, (char*)&counter->counter->variance, 4) || | |
- !write_buffer_to_socket (socketfd, (char*)&counter->index, 2)) | |
- goto cleanup; | |
- } | |
+ g_warning ("opening connection"); | |
if (!do_hello(socketfd)) | |
goto cleanup; | |
@@ -509,6 +491,9 @@ mono_counters_agent_sampling_thread (void* ptr) | |
if (!do_remove_counter (socketfd)) | |
goto cleanup; | |
break; | |
+ case 127: | |
+ g_warning ("closing connection"); | |
+ goto cleanup; | |
default: | |
g_warning ("Unknown perf-agent command %d", cmd); | |
} | |
@@ -546,10 +531,10 @@ parse_configuration (const gchar* configuration) | |
interval = strtoll (opt, NULL, 10); | |
} | |
} | |
- | |
+ | |
parse_counters_names(counters_names); | |
parse_address(address); | |
- | |
+ | |
g_free((void*)counters_names); | |
g_free((void*)address); | |
g_strfreev(opts); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment