* PQgetCancel: get a PGcancel structure corresponding to a connection. * * A copy is needed to be able to cancel a running query from a different * thread. If the same structure is used all structure members would have * to be individually locked (if the entire structure was locked, it would * be impossible to cancel a synchronous query because the structure would * have to stay locked for t
| 4514 | * have to stay locked for the duration of the query). |
| 4515 | */ |
| 4516 | PGcancel * |
| 4517 | PQgetCancel(PGconn *conn) |
| 4518 | { |
| 4519 | PGcancel *cancel; |
| 4520 | |
| 4521 | if (!conn) |
| 4522 | return NULL; |
| 4523 | |
| 4524 | if (conn->sock == PGINVALID_SOCKET) |
| 4525 | return NULL; |
| 4526 | |
| 4527 | cancel = malloc(sizeof(PGcancel)); |
| 4528 | if (cancel == NULL) |
| 4529 | return NULL; |
| 4530 | |
| 4531 | memcpy(&cancel->raddr, &conn->raddr, sizeof(SockAddr)); |
| 4532 | cancel->be_pid = conn->be_pid; |
| 4533 | cancel->be_key = conn->be_key; |
| 4534 | |
| 4535 | return cancel; |
| 4536 | } |
| 4537 | |
| 4538 | /* PQfreeCancel: free a cancel structure */ |
| 4539 | void |
no outgoing calls