Wip_write returns -1

Hello,

I try to write to an SSL socket more than 5000 bytes. The wip_write function returns as error code -1. This is not described in the help. What does -1 means in this case?
Writing less than 5000 bytes, it succeed. Why it is not possible to write more than 5000 bytes? I excpect, that the write function would return the number of bytes actually written bytes and I have to use the wip_write funtion again. But instead of thi sit retunrs -1.

Strange…

Never tried this before… but yes, the error -1 is not documented… need to check is it a limitation or not… i’ll test it and keep you updated…

So far I closed the socket after an write error.
Now I don’t do it and see, that after the wip_write returned -1 the WIP_CEV_WRITE event is raised again and I am able to write more than 5000 bytes (even 10000 bytes).

  • WIP_CEV_WRITE event
  • wip_write(socket, buffer, 10000) --> -1
  • WIP_CEV_WRITE event
  • wip_write(socket, buffer, 10000) --> successfully written 10000 bytes

Now I checked the WIP_COPT_SND_BUFSIZE with the wip_getOpts function. It is set to 5.840. The size of my buffer is 10.000. So it is not surprising, that the writing failed.
But why it fails with -1.

Writing also fails with -1, after reducing my buffer to 5814.
A buffer of 5776 bytes, can be successfully written the first time. After the next WIP_CEV_WRITE event wip_writes fails with -1.

I tried to increase the send buffer size. But the wip_setOpts fails with -1, whether I set the buffer to more than 5840 bytes or the buffer is smaller than 5840 bytes.

Hi,

can u share the piece of code?

Here wip_write returns -1

static u8 snd_buffer[BUFFER_SIZE];
static u8 snd_buffer2[BUFFER_SIZE];

case WIP_CEV_WRITE: {
		int nwrite;
		TRACE((2, "(evh): WIP_CEV_WRITE: Can send more data"));

		if (snd_length > 0)
		{
			TRACE((2, "(evh): WIP_CEV_WRITE: Trying to send %d Bytes of Data (%d)", snd_length, writeErrors));
			nwrite = wip_write(channel, snd_buffer, snd_length);

			if (nwrite >= 0) {
				TRACE((2, "(evh): WIP_CEV_WRITE: Written %d Bytes", nwrite));
				snd_length -= nwrite;
				TRACE((1, "%d bytes written to the server (%d still need to be sent)", nwrite, snd_length));
				wm_memcpy(snd_buffer2, snd_buffer + nwrite, snd_length);
				wm_memcpy(snd_buffer, snd_buffer2, snd_length);
			} else {
				writeErrors++;
				TRACE((1, "ERROR: (evh): WIP_CEV_WRITE: Write Error: %d (%d)", nwrite, writeErrors));
				switch (nwrite)
				{
					case WIP_CERR_CSTATE:
						TRACE((1, "ERROR: could not write to the server, because channel is not ready to write data (still in initialization, or is already closed)"));
						break;
					case WIP_CERR_NOT_SUPPORTED:
						TRACE((1, "ERROR: could not write to the server, because the channel does not support data writing"));
						break;
					default:
						TRACE((1, "ERROR: could not write to the server"));
						break;
				}
				send_allowed = 0;
			}
		}
		else
		{
			TRACE((2, "(evh): WIP_CEV_WRITE: Nothing to send"));
			TRACE((1, "Nothing to send"));
		}
}

Here wip_setOpts returns -1

UINT32 sndBufSize = 1000;
	UINT32 sndLowAt = 0;
	BOOL noDelay = TRUE;
	INT8 ret;
	ret = wip_setOpts(socket,
			WIP_COPT_SND_BUFSIZE, sndBufSize,
			WIP_COPT_SND_LOWAT, sndLowAt,
			WIP_COPT_NODELAY, noDelay,
			WIP_COPT_END);

i tried the sample code what we have… i am not facing any issues… if i try to write the data more than the snd buffer size… the write event is coming…

which FW … module are you using?

I’m using the module FXT009 with the firmware 7.52.0.201404040850 (Internet Library Package Version 5.56.0.201305170830; Security Library Package Version 2.2.0.201306261000).

What do you mean with ‘the write event is coming’? The WIP_CEV_WRITE event?

The WIP_CEV_WRITE is received in the event handler.
wip_write(channel, large_buffer, 10000); returns -1.
The WIP_CEV_WRITE event is coming again after wip_write failed.
After several mistrials with wip_write, the wip_write function returns the successfully written number of bytes.