# How to shut down WIP correctly

**URL:** <https://forum.sierrawireless.com/t/how-to-shut-down-wip-correctly/1012>\
**Category:** Open AT\
**Created:** [January 15, 2007, 10:03am UTC](https://forum.sierrawireless.com/t/how-to-shut-down-wip-correctly/1012 "2007-01-15T10:03:48Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![wstebel](https://avatars.discourse-cdn.com/v4/letter/w/ad7895/32.png) [@wstebel](https://forum.sierrawireless.com/u/wstebel)\
**Post date:** [January 15, 2007, 10:03am UTC](https://forum.sierrawireless.com/t/how-to-shut-down-wip-correctly/1012/1 "2007-01-15T10:03:48Z")

</div>

Hi all,

in difficult conditions it is possible that I can’t get a connection with:  
wip\_netInit ()  
wip\_bearerOpen ()  
etc…

at the first try (using GPRS).  
Second possibility is, that the connection is shut down during operation due to lost GPRS connection.

In those cases i try to disconnect correctly via:

wip\_close ( io\_channel );

wip\_bearerStop ( &bearer );

On wip\_bearerStop i get an error.

So the question is, how to shut down the GPRS wip connection correctly.  
I have tried several other sequences including wip\_close, wip\_bearerStop, wip\_bearerClose without any luck but several RTK errors.

Thanks for your help

Wolfram

---

<div class="post-metadata">

**Author:** ![tobias](https://avatars.discourse-cdn.com/v4/letter/t/c67d28/32.png) [@tobias](https://forum.sierrawireless.com/u/tobias)\
**Post date:** [January 15, 2007, 2:03pm UTC](https://forum.sierrawireless.com/t/how-to-shut-down-wip-correctly/1012/2 "2007-01-15T14:03:52Z")

</div>

You can only use wip\_bearerStop on a bearer that you have previously started with wip\_bearerStart.

wip\_bearerOpen/wip\_bearerClose is a “pair”  
wip\_bearerStart/wip\_bearerStop is a “pair”

Normal would be

wip\_netInit()  
wip\_bearerOpen()  
wip\_bearerStart()  
…  
wip\_bearerStop()  
wip\_bearerClose()

You should also take care to look at the events that your event handler receives, for example when you lose GPRS.

If a bearer has been stopped due to disconnection you should have received an event to that effect and should know if you need to do wip\_bearerStop or not.

---

<div class="post-metadata">

**Author:** ![wstebel](https://avatars.discourse-cdn.com/v4/letter/w/ad7895/32.png) [@wstebel](https://forum.sierrawireless.com/u/wstebel)\
**Post date:** [February 2, 2007, 4:04pm UTC](https://forum.sierrawireless.com/t/how-to-shut-down-wip-correctly/1012/3 "2007-02-02T16:04:31Z")

</div>

I’m still fighting this.  
I followed the tip for paired functions but I still get RTK errors.  
Do i need to call wip\_shutdown paired to wip\_TCPClientCreate too?  
If not, what else?

Log:

channel closed (with wip\_shutdown)  
bearer stop (wip\_bearerStop)  
\_BAD\_HDL (for wip\_bearerStop)  
\_BAD\_HDL ( for wip\_bearerClose)  
wip\_netExit  
…  
RTK

The same, when not calling wip\_shutdown.

Thanks for your help

---

<div class="post-metadata">

**Author:** ![wstebel](https://avatars.discourse-cdn.com/v4/letter/w/ad7895/32.png) [@wstebel](https://forum.sierrawireless.com/u/wstebel)\
**Post date:** [February 5, 2007, 12:21pm UTC](https://forum.sierrawireless.com/t/how-to-shut-down-wip-correctly/1012/4 "2007-02-05T12:21:02Z")

</div>

Hi list,

as many of you will have seen that

wip\_bearerStop ( &bearer );

is a dumb, it needs to be “bearer”, not “&bearer”.

I’m closer to the solution now, but one thing is left:

The sequence

wip\_bearerStop  
wip\_bearerClose

shows WIP\_BERR\_BAD\_STATE for the close statement.  
Do i need a delay in this sequence?

Thanks  
Wolfram

---

<div class="post-metadata">

**Author:** ![tomalex](https://avatars.discourse-cdn.com/v4/letter/t/71e660/32.png) [@tomalex](https://forum.sierrawireless.com/u/tomalex)\
**Post date:** [February 5, 2007, 5:00pm UTC](https://forum.sierrawireless.com/t/how-to-shut-down-wip-correctly/1012/5 "2007-02-05T17:00:43Z")

</div>

Hello,

If i am correct, the bearerClose() function will stop the associated bearer and close as well but you will not get the WIP\_BEV\_STOPPED event in your bearer handle. If you only call the bearerStop() function it will stop the bearer but the recources will not be freed and you will get the WIP\_BEV\_STOPPED event.

Strange, because i don’t see the WIP\_BERR\_BAD\_STATE return code in the documentation for the bearerClose() function (WIPlib 1.10). Which version do you use?

Best Regards,

tom

---

<div class="post-metadata">

**Author:** ![wstebel](https://avatars.discourse-cdn.com/v4/letter/w/ad7895/32.png) [@wstebel](https://forum.sierrawireless.com/u/wstebel)\
**Post date:** [February 6, 2007, 9:15am UTC](https://forum.sierrawireless.com/t/how-to-shut-down-wip-correctly/1012/6 "2007-02-06T09:15:25Z")

</div>

We use the newest of wavecom openat (4.11, IDE 1.02.03) and WipLib 1.10.02.  
I always check for non documented result codes 🙂. Did they promise a complete documentation?😃

I tried to call bearerClose only, but this leads to a RTK error again.  
Using wip\_bearerStop only results in \_OK\_INPROGRESS, not showing WIP\_BEV\_STOPPED at all.  
I have a bearerClose in the eventHandler for WIP\_BEV\_STOPPED that is never called.

For safety i think, i better stay with bearerStop AND bearerClose in the hope that \_BAD\_STATE is not realy true.

Any other ideas?  
Thanks for your help!

Wolfram

---

<div class="post-metadata">

**Author:** ![Tam](https://avatars.discourse-cdn.com/v4/letter/t/ba9def/32.png) [@Tam](https://forum.sierrawireless.com/u/Tam)\
**Post date:** [May 28, 2007, 1:56pm UTC](https://forum.sierrawireless.com/t/how-to-shut-down-wip-correctly/1012/7 "2007-05-28T13:56:03Z")

</div>

Hi,  
I also have a RTK exception problem on wip\_bearerStop function. It happens most of the time but not always… It looks like a wip librairy or OS bug… I’m working on a Q2686H under OS4.12, 6.61 and wip 1.10.03. Have you solve this issue since your last mail ? Thanks.  
Tam

---

<div class="post-metadata">

**Author:** ![wstebel](https://avatars.discourse-cdn.com/v4/letter/w/ad7895/32.png) [@wstebel](https://forum.sierrawireless.com/u/wstebel)\
**Post date:** [May 29, 2007, 7:12am UTC](https://forum.sierrawireless.com/t/how-to-shut-down-wip-correctly/1012/8 "2007-05-29T07:12:48Z")

</div>

Hi all,  
i already solved this problem.  
The most important part is, not to close wip at all.  
In my case i need a timer controlled start routine for wip and for the tcp connection, so that under rough conditions i can always reconnect.

sequenz:

try wip-connect sequence  
-\>error: start wip-reconnect timer  
-\>success: try to start tcp client

try tcp-connect sequence  
-\>error: start tcp reconnect timer  
-\>success: start transfering data

tcp-disconnect/close  
-\>start tcp reconnect timer

wip-disconnect/close  
-\>start wip reconnect timer

Call wip\_bearerClose on wip-handler messages that require it, but call wip\_bearerStop only on a manually invoked shutdown.

For the communication itself i only use

wip\_TCPClientCreate  
and  
wip\_close

as a flow control, never touching the lower leveled wip-functions, when i can avoid it.

Thats how it works for me.

HTH

Wolfram

---

<div class="post-metadata">

**Author:** ![afaurep](https://avatars.discourse-cdn.com/v4/letter/a/9d8465/32.png) [@afaurep](https://forum.sierrawireless.com/u/afaurep)\
**Post date:** [August 8, 2007, 4:08pm UTC](https://forum.sierrawireless.com/t/how-to-shut-down-wip-correctly/1012/9 "2007-08-08T16:08:00Z")

</div>

hy,

i have the same error. i use HTTP library. Here is my HTTP Handler :

```auto
void BL_GPRS_HTTP_Hdlr(wip_event_t *ev, void *ctx){
    
    wip_channel_t tChannel;
    tChannel = ev->channel;
    u32 * ret;
    
    switch(ev->kind){
        
        case WIP_CEV_OPEN :         
            ...
            break;
            
        case WIP_CEV_READ :         
            ...
            break;
            
        case WIP_CEV_WRITE :   
            ...
            break;
            
        case WIP_CEV_ERROR :                   
        case WIP_CEV_PEER_CLOSE :               
            wip_getOpts(tChannel, WIP_COPT_HTTP_STATUS_CODE, &ret, WIP_COPT_END);
            if(ret != 200){
                TRACE((1,"Result Code %d", ret));
            }
            wip_close(tChannel);
            wip_bearerStop(myBearer);          
            break; 
           
        default :
           break;    
    }
```

With this code, i’m able to do several request to my server. When WIP\_CEV\_PEER\_CLOSE event occured with a succesfully HTTP request :

- HTTP result Code is 200
- HTTP Channel close properly (wip\_close())
- bearerStop() properly too
- WIP\_BEV\_STOPPED event occured and here i use bearerClose()

So, in this case all it’s right.

But, when WIP\_CEV\_ERROR event occured or WIP\_CEV\_PEER\_CLOSE event with HTTP result Code return an error (for e.g. HTTP error 400)

- HTTP Channel close properly (wip\_close())
- but bearerStop() will reset the module.

Why module reset ? it seems that when an error occured (HTTP error or WIP\_CEV\_ERROR), you shouldn’t close bearer at all. But why ? If bearer not closed after an error, how can i do a HTTP communication next times ???  
Can someone help me or explain to me how bearerStop() / bearerClose() / wip\_close() working ?!

Thank in advance.

Regards
