MCPcopy Create free account
hub / github.com/bloomberg/comdb2 / cdb2_socket_pool_donate_ext

Function cdb2_socket_pool_donate_ext

cdb2api/cdb2api.c:2084–2154  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2082}
2083
2084void cdb2_socket_pool_donate_ext(const char *typestr, int fd, int ttl,
2085 int dbnum)
2086{
2087 int enabled = 0;
2088 int sockpool_fd = -1;
2089 int sp_generation = -1;
2090
2091 pthread_mutex_lock(&cdb2_sockpool_mutex);
2092 enabled = sockpool_enabled;
2093 if (enabled == 1) {
2094 sockpool_fd = sockpool_get_from_pool();
2095 sp_generation = sockpool_generation;
2096 }
2097 pthread_mutex_unlock(&cdb2_sockpool_mutex);
2098
2099 if (enabled == 1) {
2100 /* Donate this socket to the global socket pool. We know that the
2101 * mutex is held. */
2102 if (sockpool_fd == -1) {
2103 sockpool_fd = open_sockpool_ll();
2104 if (sockpool_fd == -1) {
2105 pthread_mutex_lock(&cdb2_sockpool_mutex);
2106 sockpool_enabled = 0;
2107 pthread_mutex_unlock(&cdb2_sockpool_mutex);
2108 fprintf(stderr, "\n Sockpool not present");
2109 }
2110 }
2111
2112 struct sockpool_msg_vers0 msg = {0};
2113 if (sockpool_fd != -1 && (strlen(typestr) < sizeof(msg.typestr))) {
2114 int rc;
2115 msg.request = SOCKPOOL_DONATE;
2116 msg.dbnum = dbnum;
2117 msg.timeout = ttl;
2118 strncpy(msg.typestr, typestr, sizeof(msg.typestr) - 1);
2119
2120 errno = 0;
2121 rc = send_fd(sockpool_fd, &msg, sizeof(msg), fd);
2122 if (rc != PASSFD_SUCCESS) {
2123 fprintf(stderr, "%s: send_fd rc %d errno %d %s\n", __func__, rc,
2124 errno, strerror(errno));
2125 pthread_mutex_lock(&cdb2_sockpool_mutex);
2126 sockpool_remove_fd(sockpool_fd);
2127 pthread_mutex_unlock(&cdb2_sockpool_mutex);
2128 close(sockpool_fd);
2129 sockpool_fd = -1;
2130 }
2131 }
2132 if (sockpool_fd != -1) {
2133 pthread_mutex_lock(&cdb2_sockpool_mutex);
2134 int closeit = 0;
2135 if (sp_generation == sockpool_generation) {
2136 if ((sockpool_place_fd_in_pool(sockpool_fd)) != 0) {
2137 closeit = 1;
2138 }
2139 } else {
2140 sockpool_remove_fd(sockpool_fd);
2141 closeit = 1;

Callers 3

newsql_disconnectFunction · 0.85
comdb2db_get_dbhostsFunction · 0.85
cdb2_dbinfo_queryFunction · 0.85

Calls 5

sockpool_get_from_poolFunction · 0.85
sockpool_remove_fdFunction · 0.85
open_sockpool_llFunction · 0.70
send_fdFunction · 0.70

Tested by

no test coverage detected