P
P
Pinkman2021-11-23 00:08:23
C++ / C#
Pinkman, 2021-11-23 00:08:23

How to remove freezes on the server using select?

I wrote a proxy server. The server is single-threaded, it works through select. I have a piece of code that blocks the server:

bool closeConnect = false;
  std::string req = _getReq(closeConnect, fd);
  try {
    _dbSock->init();
    _dbSock->connectTo();
  } catch (std::exception &e) {
    std::cerr << "DB sock: " << e.what() << std::endl;
    closeConnect = true;
  }
  if (!closeConnect) {
    send(_dbSock->getSocket(), req.c_str(), req.size(), 0);
    bool tmp;
    req.erase();
    req = _getReq(tmp, _dbSock->getSocket());
    std::cerr << req.size();
    send(fd, req.c_str(), req.length(), 0);
  }

I know that it is blocked at the moment of communication with the database, but I don’t understand how to fix it? I tried first to open a socket for the db, and add it to fd_set, but, most likely, I did it somehow wrong, because in general everything stopped working.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question