Skip to content
Snippets Groups Projects
Commit ccf6937a authored by chezhaocheng ubuntu server's avatar chezhaocheng ubuntu server
Browse files

in debug

parent 830c5396
No related branches found
No related tags found
No related merge requests found
Pipeline #63283 failed with stage
# Untracked Files
/tags
src/runtime/testoptions.h
src/runtime-glue/testoptions.h
# Untracked Directories
doc/html
......@@ -47,7 +47,7 @@
* for a good description.
-----------------------------------------------------------------------------*/
static const int numaccept = 2;
static const int numaccept = 1;
static bool server = false;
static int numconn = std::max(2,numaccept);
......@@ -73,6 +73,7 @@ static void opts(int argc, char** argv, sockaddr_in& addr) {
break;
case 'c':
numconn = atoi(optarg);
std::cout << "numconn " << numconn << std::endl;
break;
case 'p':
addr.sin_port = htons(atoi(optarg));
......@@ -120,17 +121,21 @@ static void servconn(void* arg) {
}
finish:
std::cout << fd << " finish recv 1" << std::endl;
// std::cout << ntohs(client.sin_port) << " done receiving" << std::endl;
// send response
SYSCALL_EQ(lfSend(fd, (const void*)&code, sizeof(code), 0), sizeof(code));
// std::cout << ntohs(client.sin_port) << " done sending" << std::endl;
std::cout << fd << " finish recv 2" << std::endl;
// wait for client closing the socket
SYSCALL_EQ(lfRecv(fd, (void*)&code, sizeof(code), 0), 0);
// std::cout << ntohs(client.sin_port) << " client closed" << std::endl;
std::cout << fd << " finish recv 3" << std::endl;
// close socket and terminate fibre
SYSCALL(lfClose(fd));
std::cout << fd << " finish recv 4" << std::endl;
}
static int servFD = -1;
......@@ -139,7 +144,9 @@ void servaccept() {
// create up to N connection handlers
Fibre** f = new Fibre*[numconn/numaccept];
for (int n = 0; n < numconn/numaccept; n += 1) {
std::cout << "tryAccept " << std::endl;
intptr_t fd = SYSCALLIO(lfAccept(servFD, nullptr, nullptr));
std::cout << "lfAccept " << fd << std::endl;
__atomic_add_fetch(&acceptcount, 1, __ATOMIC_RELAXED);
if (acceptcount == pausecount) {
Context::CurrCluster().pause();
......@@ -173,6 +180,7 @@ void servaccept2(void*) {
void servmain(sockaddr_in& addr) {
// create server socket
servFD = SYSCALLIO(lfSocket(AF_INET, SOCK_STREAM, 0));
std::cout << "servFD created " << servFD << std::endl;
int on = 1;
SYSCALL(setsockopt(servFD, SOL_SOCKET, SO_REUSEADDR, (const void*)&on, sizeof(int)));
......@@ -184,7 +192,7 @@ void servmain(sockaddr_in& addr) {
SYSCALL(getsockname(servFD, (sockaddr*)&addr, &addrlen));
std::cout << "listening on " << inet_ntoa(addr.sin_addr) << ':' << ntohs(addr.sin_port) << std::endl;
SYSCALL(lfListen(servFD, numconn));
std::cout << "HERE" << std::endl;
{
Context::CurrCluster().addWorkers(2);
Fibre a1(Context::CurrCluster(), true);
......@@ -206,13 +214,14 @@ void servmain(sockaddr_in& addr) {
void clientconn(sockaddr_in* server) {
// create client socket and connect to server
int fd = SYSCALLIO(lfSocket(AF_INET, SOCK_STREAM, 0));
// std::cout << "connecting to " << inet_ntoa(server->sin_addr) << ':' << ntohs(server->sin_port) << std::endl;
std::cout << "connecting to " << inet_ntoa(server->sin_addr) << ':' << ntohs(server->sin_port) << std::endl;
SYSCALL(lfConnect(fd, (sockaddr*)server, sizeof(sockaddr_in)));
std::cout << "connected at " << fd << std::endl;
struct sockaddr_in local;
socklen_t addrlen = sizeof(local);
SYSCALL(getsockname(fd, (sockaddr*)&local, &addrlen));
// std::cout << "connected from " << inet_ntoa(local.sin_addr) << ':' << ntohs(local.sin_port) << std::endl;
std::cout << "connected from " << inet_ntoa(local.sin_addr) << ':' << ntohs(local.sin_port) << std::endl;
char code = 0;
int32_t bcount;
......@@ -260,5 +269,6 @@ int main(int argc, char** argv) {
FibreInit();
if (server) servmain(addr);
else clientmain(addr);
std::cerr << "FINISH" << std::endl;
return 0;
}
......@@ -170,15 +170,18 @@ class EventScope {
#else
static const Poller::Variant variant = Input ? Poller::Edge : Poller::Oneshot;
#endif
//std::cout << "First try start " << fd << std::endl;
#if TESTING_IO_TRYFIRST
if (Yield) Fibre::yield();
if (tryIO<Input>(ret, iofunc, fd, a...)) return ret;
#else
if (!Input && tryIO<Input>(ret, iofunc, fd, a...)) return ret;
#endif
std::cout << "First try fail " << fd << std::endl;
BasePoller*& poller = fdSyncVector[fd].poller[Input];
#if TESTING_EVENTPOLL_MEMO
if (Input && !poller) {
std::cout << "syncIO getPoller " << fd << std::endl;
poller = &getPoller<Input,Cluster>(fd);
poller->setupFD(fd, static_cast<Poller::Operation>(
static_cast<int>(Poller::Create) | static_cast<int>(Poller::Memo)
......@@ -193,8 +196,12 @@ class EventScope {
}
Poller::SyncSem& sync = fdSyncVector[fd].sync[Input];
for (;;) {
std::cout << "syncIO Wait " << fd << std::endl;
if (variant == Poller::Level) sync.wait(); else sync.P();
if (tryIO<Input>(ret, iofunc, fd, a...)) return ret;
std::cout << "syncIO Wake " << fd << std::endl;
if (tryIO<Input>(ret, iofunc, fd, a...)) // return ret;
{// printf("Finish tryIO %d\n", fd);
return ret;}
#if TESTING_EVENTPOLL_MEMO
if (Input) {} else
#endif
......@@ -209,6 +216,7 @@ class EventScope {
fdsync.poller[false] = &getPoller<false,false>(fd);
fdsync.poller[false]->setupFD(fd, Poller::Create, Poller::Output, Poller::Oneshot); // register immediately
fdsync.sync[false].P(); // wait for completion
std::cout << "checkAsyncCompletion Wake " << std::endl;
int err;
socklen_t sz = sizeof(err);
SYSCALL(getsockopt(fd, SOL_SOCKET, SO_ERROR, &err, &sz));
......@@ -440,6 +448,8 @@ public:
: ::accept4(fd, addr, addrlen, flags);
} else
#endif
std::cout << "lfAccept Invoked" << std::endl;
std::cout << "accept4 is blocking ?" << fdSyncVector[fd].blocking << std::endl;
ret = fdSyncVector[fd].blocking
? syncIO<true,false,true>(::accept4, fd, addr, addrlen, flags | SOCK_NONBLOCK)
: ::accept4(fd, addr, addrlen, flags | SOCK_NONBLOCK);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment