I am not using raw api now, but...
Check what tcp_write and tcp_output returns, are the err's ERR_OK? For first and second call?
It looks like you can receive only the bytes that fill into sndbuf free space.
Than try 2 options, first:
1) check how much space you have in sendbuf (len)
2) take exacly that amount of data and do tcp_write, (change pointer)
3) force send with tcp_output
4) after tcp_output check sendbuff free space again - how much space is there now? If there are no free space - maybie try to hardcode a simple wait/delay and check sendbuf after some time?
Alternate option:
1) check how much space you have in sendbuf (len)
2) take exacly that amount of data and do tcp_write
3) force send with tcp_output
4) wait for sent callback
5) got to point 1 but with rest of the data.
Dominik