| 914 | } |
| 915 | |
| 916 | void fxSend(txMachine* the, txBoolean flags) |
| 917 | { |
| 918 | struct tcp_pcb *pcb = the->connection; |
| 919 | txBoolean more = 0 != (flags & 1); |
| 920 | txBoolean binary = 0 != (flags & 2); |
| 921 | |
| 922 | xmodLog(" fxSend - ENTER"); |
| 923 | |
| 924 | if (!pcb) return; |
| 925 | |
| 926 | if (kSerialConnection != pcb) { |
| 927 | /* int length = the->echoOffset; |
| 928 | const char *bytes = the->echoBuffer; |
| 929 | err_t err; |
| 930 | uint8_t sentHeader = 0; |
| 931 | |
| 932 | xmodLog(" fxSend - about to loop"); |
| 933 | |
| 934 | while (length && the->connection) { |
| 935 | u16_t available = tcp_sndbuf(pcb); |
| 936 | if ((0 == available) || (!sentHeader && (available < 4))) { |
| 937 | xmodLog(" fxSend - need to wait"); |
| 938 | tcp_output_safe(pcb); |
| 939 | modWatchDogReset(); |
| 940 | modDelayMilliseconds(10); |
| 941 | continue; |
| 942 | } |
| 943 | |
| 944 | if (!sentHeader) { |
| 945 | uint8_t header[4]; |
| 946 | header[0] = (the->wsSendStart ? (binary ? 0x02 : 0x01) : 0) | (more ? 0 : 0x80); |
| 947 | the->wsSendStart = !more; |
| 948 | if (length < 126) { |
| 949 | header[1] = (uint8_t)length; |
| 950 | sentHeader = 2; |
| 951 | } |
| 952 | else { |
| 953 | header[1] = 126; |
| 954 | header[2] = length >> 8; |
| 955 | header[3] = length & 0xff; |
| 956 | sentHeader = 4; |
| 957 | } |
| 958 | tcp_write_safe(pcb, header, sentHeader, more ? (TCP_WRITE_FLAG_MORE | TCP_WRITE_FLAG_COPY) : TCP_WRITE_FLAG_COPY); |
| 959 | available -= sentHeader; |
| 960 | if (0 == available) |
| 961 | continue; |
| 962 | } |
| 963 | |
| 964 | if (available > length) |
| 965 | available = length; |
| 966 | |
| 967 | while (the->connection) { |
| 968 | modWatchDogReset(); |
| 969 | err = tcp_write_safe(pcb, bytes, available, more ? (TCP_WRITE_FLAG_MORE | TCP_WRITE_FLAG_COPY) : TCP_WRITE_FLAG_COPY); |
| 970 | if (ERR_MEM == err) { |
| 971 | xmodLog(" fxSend - wait for send memory:"); |
| 972 | tcp_output_safe(pcb); |
| 973 | modDelayMilliseconds(10); |
no test coverage detected