# Wip\_write returns -1

**URL:** <https://forum.sierrawireless.com/t/wip-write-returns-1/7336>\
**Category:** Open AT\
**Created:** [July 24, 2014, 11:58am UTC](https://forum.sierrawireless.com/t/wip-write-returns-1/7336 "2014-07-24T11:58:53Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![mandy](https://avatars.discourse-cdn.com/v4/letter/m/b4bc9f/32.png) [@mandy](https://forum.sierrawireless.com/u/mandy)\
**Post date:** [July 24, 2014, 11:58am UTC](https://forum.sierrawireless.com/t/wip-write-returns-1/7336/1 "2014-07-24T11:58:53Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Rex\_alex](https://avatars.discourse-cdn.com/v4/letter/r/73ab20/32.png) [@Rex\_alex](https://forum.sierrawireless.com/u/Rex_alex)\
**Post date:** [July 30, 2014, 1:39pm UTC](https://forum.sierrawireless.com/t/wip-write-returns-1/7336/2 "2014-07-30T13:39:17Z")

</div>

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…

---

<div class="post-metadata">

**Author:** ![mandy](https://avatars.discourse-cdn.com/v4/letter/m/b4bc9f/32.png) [@mandy](https://forum.sierrawireless.com/u/mandy)\
**Post date:** [July 31, 2014, 6:04am UTC](https://forum.sierrawireless.com/t/wip-write-returns-1/7336/3 "2014-07-31T06:04:02Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![mandy](https://avatars.discourse-cdn.com/v4/letter/m/b4bc9f/32.png) [@mandy](https://forum.sierrawireless.com/u/mandy)\
**Post date:** [August 13, 2014, 8:31am UTC](https://forum.sierrawireless.com/t/wip-write-returns-1/7336/4 "2014-08-13T08:31:26Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Rex\_alex](https://avatars.discourse-cdn.com/v4/letter/r/73ab20/32.png) [@Rex\_alex](https://forum.sierrawireless.com/u/Rex_alex)\
**Post date:** [August 13, 2014, 2:02pm UTC](https://forum.sierrawireless.com/t/wip-write-returns-1/7336/5 "2014-08-13T14:02:30Z")

</div>

Hi,

can u share the piece of code?

---

<div class="post-metadata">

**Author:** ![mandy](https://avatars.discourse-cdn.com/v4/letter/m/b4bc9f/32.png) [@mandy](https://forum.sierrawireless.com/u/mandy)\
**Post date:** [August 13, 2014, 2:17pm UTC](https://forum.sierrawireless.com/t/wip-write-returns-1/7336/6 "2014-08-13T14:17:02Z")

</div>

Here wip\_write returns -1

```auto
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

```auto
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);
```

---

<div class="post-metadata">

**Author:** ![Rex\_alex](https://avatars.discourse-cdn.com/v4/letter/r/73ab20/32.png) [@Rex\_alex](https://forum.sierrawireless.com/u/Rex_alex)\
**Post date:** [September 17, 2014, 1:02pm UTC](https://forum.sierrawireless.com/t/wip-write-returns-1/7336/7 "2014-09-17T13:02:00Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![mandy](https://avatars.discourse-cdn.com/v4/letter/m/b4bc9f/32.png) [@mandy](https://forum.sierrawireless.com/u/mandy)\
**Post date:** [September 17, 2014, 1:27pm UTC](https://forum.sierrawireless.com/t/wip-write-returns-1/7336/8 "2014-09-17T13:27:20Z")

</div>

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.
