------------------------------------------------------------------------- transform_handler Handler for all events received during the transformation process Input: contp continuation for the current transaction event event received data pointer on optional data Output : Return Value: -------------------------------------------------------------------------
| 734 | Return Value: |
| 735 | -------------------------------------------------------------------------*/ |
| 736 | static int |
| 737 | transform_handler(TSCont contp, TSEvent event, void *edata ATS_UNUSED) |
| 738 | { |
| 739 | ContData *data; |
| 740 | int state, retval; |
| 741 | |
| 742 | /* This section will be called by both TS internal |
| 743 | and the thread. Protect it with a mutex to avoid |
| 744 | concurrent calls. */ |
| 745 | |
| 746 | /* Handle TryLock result */ |
| 747 | if (TSMutexLockTry(TSContMutexGet(contp)) != TS_SUCCESS) { |
| 748 | TSCont c = TSContCreate(trylock_handler, nullptr); |
| 749 | auto d = TSRalloc<TryLockData>(); |
| 750 | |
| 751 | d->contp = contp; |
| 752 | d->event = event; |
| 753 | TSContDataSet(c, d); |
| 754 | TSContScheduleOnPool(c, 10, TS_THREAD_POOL_NET); |
| 755 | return 1; |
| 756 | } |
| 757 | |
| 758 | data = contDataGet(contp); |
| 759 | TSAssert(data->magic == MAGIC_ALIVE); |
| 760 | |
| 761 | state = data->state; |
| 762 | |
| 763 | /* Check to see if the transformation has been closed */ |
| 764 | retval = TSVConnClosedGet(contp); |
| 765 | if (retval) { |
| 766 | /* If the thread is still executing its job, we don't want to destroy |
| 767 | the continuation right away as the thread will call us back |
| 768 | on this continuation. */ |
| 769 | if (state == STATE_READ_PSI) { |
| 770 | TSContScheduleOnPool(contp, 10, TS_THREAD_POOL_NET); |
| 771 | } else { |
| 772 | TSMutexUnlock(TSContMutexGet(contp)); |
| 773 | cont_data_destroy(contDataGet(contp)); |
| 774 | TSContDestroy(contp); |
| 775 | return 1; |
| 776 | } |
| 777 | } else { |
| 778 | TSVIO input_vio; |
| 779 | switch (event) { |
| 780 | case TS_EVENT_ERROR: |
| 781 | input_vio = TSVConnWriteVIOGet(contp); |
| 782 | TSContCall(TSVIOContGet(input_vio), TS_EVENT_ERROR, input_vio); |
| 783 | break; |
| 784 | |
| 785 | case TS_EVENT_VCONN_WRITE_COMPLETE: |
| 786 | TSVConnShutdown(TSTransformOutputVConnGet(contp), 0, 1); |
| 787 | break; |
| 788 | |
| 789 | case TS_EVENT_VCONN_WRITE_READY: |
| 790 | /* downstream vconnection is done reading data we've write into it. |
| 791 | let's read some more data from upstream if we're in read state. */ |
| 792 | if (state == STATE_READ_DATA) { |
| 793 | handle_transform(contp); |
no test coverage detected