diff --git a/core/dcb.c b/core/dcb.c index 7ddc51b9b..e1068a69d 100644 --- a/core/dcb.c +++ b/core/dcb.c @@ -262,10 +262,15 @@ DCB *ptr, *lptr; /** * Connect to a server + * + * This routine will create a server connection + * If succesful the new dcb will be put in + * epoll set by dcb->func.connect * * @param server The server to connect to * @param session The session this connection is being made for * @param protocol The protocol module to use + * @return The new allocated dcb */ DCB * dcb_connect(SERVER *server, SESSION *session, const char *protocol) @@ -294,10 +299,14 @@ GWPROTOCOL *funcs; server->name, server->port, dcb); return NULL; } + + /* + * The dcb will be addded into poll set by dcb->func.connect + */ + atomic_add(&server->stats.n_connections, 1); atomic_add(&server->stats.n_current, 1); - poll_add_dcb(dcb); /* * We are now connected, the authentication etc will happen as * part of the EPOLLOUT event that will be received once the connection diff --git a/modules/protocol/mysql_common.c b/modules/protocol/mysql_common.c index 667ef955f..eaec4bbd4 100644 --- a/modules/protocol/mysql_common.c +++ b/modules/protocol/mysql_common.c @@ -484,12 +484,25 @@ int gw_do_connect_to_backend(char *host, int port, MySQLProtocol *conn) { return -1; } + /* Assign so to the caller dcb, conn->descriptor */ + + conn->descriptor->fd = so; + + /** + * Add the dcb in the poll set + */ + + poll_add_dcb(conn->descriptor); + + /* prepare for connect */ + setipaddress(&serv_addr.sin_addr, host); serv_addr.sin_port = htons(port); /* set NON BLOCKING here */ setnonblocking(so); + /* do the connect */ if ((rv = connect(so, (struct sockaddr *)&serv_addr, sizeof(serv_addr))) < 0) { /* If connection is not yet completed just return 1 */ if (errno == EINPROGRESS) {