* Handle end of the copy stream. */
| 1175 | * Handle end of the copy stream. |
| 1176 | */ |
| 1177 | static PGresult * |
| 1178 | HandleEndOfCopyStream(PGconn *conn, StreamCtl *stream, char *copybuf, |
| 1179 | XLogRecPtr blockpos, XLogRecPtr *stoppos) |
| 1180 | { |
| 1181 | PGresult *res = PQgetResult(conn); |
| 1182 | |
| 1183 | /* |
| 1184 | * The server closed its end of the copy stream. If we haven't closed |
| 1185 | * ours already, we need to do so now, unless the server threw an error, |
| 1186 | * in which case we don't. |
| 1187 | */ |
| 1188 | if (still_sending) |
| 1189 | { |
| 1190 | if (!close_walfile(stream, blockpos)) |
| 1191 | { |
| 1192 | /* Error message written in close_walfile() */ |
| 1193 | PQclear(res); |
| 1194 | return NULL; |
| 1195 | } |
| 1196 | if (PQresultStatus(res) == PGRES_COPY_IN) |
| 1197 | { |
| 1198 | if (PQputCopyEnd(conn, NULL) <= 0 || PQflush(conn)) |
| 1199 | { |
| 1200 | pg_log_error("could not send copy-end packet: %s", |
| 1201 | PQerrorMessage(conn)); |
| 1202 | PQclear(res); |
| 1203 | return NULL; |
| 1204 | } |
| 1205 | res = PQgetResult(conn); |
| 1206 | } |
| 1207 | still_sending = false; |
| 1208 | } |
| 1209 | if (copybuf != NULL) |
| 1210 | PQfreemem(copybuf); |
| 1211 | *stoppos = blockpos; |
| 1212 | return res; |
| 1213 | } |
| 1214 | |
| 1215 | /* |
| 1216 | * Check if we should continue streaming, or abort at this point. |
no test coverage detected