/** * Handler for the EPOLLIN event when the DCB refers to the listening * socket for the protocol. * * @param dcb The descriptor control block * @return The number of new connections created */ static int telnetd_accept(DCB *dcb) { int n_connect = 0; while (1) { int so; struct sockaddr_in addr; socklen_t addrlen = sizeof(struct sockaddr); DCB *client_dcb; TELNETD* telnetd_pr = NULL; dcb_state_t old_state = DCB_STATE_UNDEFINED; bool succp = FALSE; so = accept(dcb->fd, (struct sockaddr *)&addr, &addrlen); if (so == -1) return n_connect; else { atomic_add(&dcb->stats.n_accepts, 1); client_dcb = dcb_alloc(DCB_ROLE_REQUEST_HANDLER); if (client_dcb == NULL) { return n_connect; } client_dcb->fd = so; client_dcb->remote = strdup(inet_ntoa(addr.sin_addr)); memcpy(&client_dcb->func, &MyObject, sizeof(GWPROTOCOL)); client_dcb->session = session_alloc(dcb->session->service, client_dcb); telnetd_pr = (TELNETD *)malloc(sizeof(TELNETD)); client_dcb->protocol = (void *)telnetd_pr; if (telnetd_pr == NULL) { dcb_add_to_zombieslist(client_dcb); return n_connect; } if (poll_add_dcb(client_dcb) == -1) { dcb_add_to_zombieslist(dcb); return n_connect; } n_connect++; telnetd_pr->state = TELNETD_STATE_LOGIN; telnetd_pr->username = NULL; dcb_printf(client_dcb, "MaxScale login: "); } } return n_connect; }
/** * test1 Allocate a dcb and do lots of other things * */ static int test1() { DCB *dcb, *extra, *clone; int size = 100; int bite1 = 35; int bite2 = 60; int bite3 = 10; int buflen; /* Single buffer tests */ ss_dfprintf(stderr, "testdcb : creating buffer with type DCB_ROLE_SERVICE_LISTENER"); dcb = dcb_alloc(DCB_ROLE_SERVICE_LISTENER); printDCB(dcb); ss_info_dassert(dcb_isvalid(dcb), "New DCB must be valid"); ss_dfprintf(stderr, "\t..done\nAllocated dcb."); clone = dcb_clone(dcb); ss_dfprintf(stderr, "\t..done\nCloned dcb"); printAllDCBs(); ss_info_dassert(true, "Something is true"); ss_dfprintf(stderr, "\t..done\n"); dcb_free(dcb); ss_dfprintf(stderr, "Freed original dcb"); ss_info_dassert(!dcb_isvalid(dcb), "Freed DCB must not be valid"); ss_dfprintf(stderr, "\t..done\nMake clone DCB a zombie"); clone->state = DCB_STATE_NOPOLLING; dcb_add_to_zombieslist(clone); ss_info_dassert(dcb_get_zombies() == clone, "Clone DCB must be start of zombie list now"); ss_dfprintf(stderr, "\t..done\nProcess the zombies list"); dcb_process_zombies(0); ss_dfprintf(stderr, "\t..done\nCheck clone no longer valid"); ss_info_dassert(!dcb_isvalid(clone), "After zombie processing, clone DCB must not be valid"); ss_dfprintf(stderr, "\t..done\n"); return 0; }