MCPcopy Create free account
hub / github.com/chenshuo/muduo / onMessage

Method onMessage

examples/sudoku/server_basic.cc:44–74  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

42 }
43
44 void onMessage(const TcpConnectionPtr& conn, Buffer* buf, Timestamp)
45 {
46 LOG_DEBUG << conn->name();
47 size_t len = buf->readableBytes();
48 while (len >= kCells + 2)
49 {
50 const char* crlf = buf->findCRLF();
51 if (crlf)
52 {
53 string request(buf->peek(), crlf);
54 buf->retrieveUntil(crlf + 2);
55 len = buf->readableBytes();
56 if (!processRequest(conn, request))
57 {
58 conn->send("Bad Request!\r\n");
59 conn->shutdown();
60 break;
61 }
62 }
63 else if (len > 100) // id + ":" + kCells + "\r\n"
64 {
65 conn->send("Id too long!\r\n");
66 conn->shutdown();
67 break;
68 }
69 else
70 {
71 break;
72 }
73 }
74 }
75
76 bool processRequest(const TcpConnectionPtr& conn, const string& request)
77 {

Callers

nothing calls this directly

Calls 6

readableBytesMethod · 0.80
findCRLFMethod · 0.80
peekMethod · 0.80
retrieveUntilMethod · 0.80
shutdownMethod · 0.80
sendMethod · 0.45

Tested by

no test coverage detected