---------------- * SocketBackend() Is called for frontend-backend connections * * Returns the message type code, and loads message body data into inBuf. * * EOF is returned if the connection is lost. * ---------------- */
| 450 | * ---------------- |
| 451 | */ |
| 452 | static int |
| 453 | SocketBackend(StringInfo inBuf) |
| 454 | { |
| 455 | int qtype; |
| 456 | int maxmsglen; |
| 457 | |
| 458 | /* |
| 459 | * Get message type code from the frontend. |
| 460 | */ |
| 461 | HOLD_CANCEL_INTERRUPTS(); |
| 462 | pq_startmsgread(); |
| 463 | qtype = pq_getbyte(); |
| 464 | |
| 465 | if (qtype == EOF) /* frontend disconnected */ |
| 466 | { |
| 467 | if (IsTransactionState()) |
| 468 | ereport(COMMERROR, |
| 469 | (errcode(ERRCODE_CONNECTION_FAILURE), |
| 470 | errmsg("unexpected EOF on client connection with an open transaction"))); |
| 471 | else |
| 472 | { |
| 473 | /* |
| 474 | * Can't send DEBUG log messages to client at this point. Since |
| 475 | * we're disconnecting right away, we don't need to restore |
| 476 | * whereToSendOutput. |
| 477 | */ |
| 478 | whereToSendOutput = DestNone; |
| 479 | ereport(DEBUG1, |
| 480 | (errcode(ERRCODE_CONNECTION_DOES_NOT_EXIST), |
| 481 | errmsg_internal("unexpected EOF on client connection"))); |
| 482 | } |
| 483 | return qtype; |
| 484 | } |
| 485 | |
| 486 | /* |
| 487 | * Validate message type code before trying to read body; if we have lost |
| 488 | * sync, better to say "command unknown" than to run out of memory because |
| 489 | * we used garbage as a length word. We can also select a type-dependent |
| 490 | * limit on what a sane length word could be. (The limit could be chosen |
| 491 | * more granularly, but it's not clear it's worth fussing over.) |
| 492 | * |
| 493 | * This also gives us a place to set the doing_extended_query_message flag |
| 494 | * as soon as possible. |
| 495 | */ |
| 496 | switch (qtype) |
| 497 | { |
| 498 | case 'Q': /* simple query */ |
| 499 | maxmsglen = PQ_LARGE_MESSAGE_LIMIT; |
| 500 | doing_extended_query_message = false; |
| 501 | break; |
| 502 | |
| 503 | case 'M': /* Apache Cloudberry dispatched statement from QD */ |
| 504 | maxmsglen = PQ_LARGE_MESSAGE_LIMIT; |
| 505 | doing_extended_query_message = false; |
| 506 | |
| 507 | /* don't support old protocols with this. */ |
| 508 | if( PG_PROTOCOL_MAJOR(FrontendProtocol) < 3 ) |
| 509 | ereport(COMMERROR, |
no test coverage detected