# FreeRTOS\_accept() Timeout

**URL:** <https://forums.freertos.org/t/freertos-accept-timeout/20788>\
**Category:** Renesas\
**Created:** [June 21, 2024, 12:41am UTC](https://forums.freertos.org/t/freertos-accept-timeout/20788 "2024-06-21T00:41:51Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![taki](https://avatars.discourse-cdn.com/v4/letter/t/ccd318/32.png) [@taki](https://forums.freertos.org/u/taki)\
**Post date:** [June 21, 2024, 12:41am UTC](https://forums.freertos.org/t/freertos-accept-timeout/20788/1 "2024-06-21T00:41:51Z")

</div>

Hello

Please tell me about FreeRTOS\_accept()

How do I put in my code to make sure that a timeout has occurred?

よろしくお願いいたします。

---

<div class="post-metadata">

**Author:** ![moninom1](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/moninom1/32/4343_2.png) [@moninom1](https://forums.freertos.org/u/moninom1)\
**Post date:** [June 21, 2024, 4:35am UTC](https://forums.freertos.org/t/freertos-accept-timeout/20788/2 "2024-06-21T04:35:27Z")

</div>

Hi @taki

FreeRTOS\_accept() has an optional timeout option. It could be used by setting receive block time on the listening socket using FreeRTOS\_setsockopt with FREERTOS\_SO\_RCVTIMEO parameter. This will set the maximum time the FreeRTOS\_accept function will block while waiting for a connection.

Please find more[information here](https://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/API/accept.html).

---

<div class="post-metadata">

**Author:** ![taki](https://avatars.discourse-cdn.com/v4/letter/t/ccd318/32.png) [@taki](https://forums.freertos.org/u/taki)\
**Post date:** [June 21, 2024, 5:03am UTC](https://forums.freertos.org/t/freertos-accept-timeout/20788/3 "2024-06-21T05:03:58Z")

</div>

Thank you for your reply.

I understand the timeout settings.

Could you please tell me how to determine from the code whether it timed out or connected?

Thank you

---

<div class="post-metadata">

**Author:** ![hs2](https://avatars.discourse-cdn.com/v4/letter/h/a4c791/32.png) [@hs2](https://forums.freertos.org/u/hs2)\
**Post date:** [June 21, 2024, 5:45am UTC](https://forums.freertos.org/t/freertos-accept-timeout/20788/4 "2024-06-21T05:45:00Z")

</div>

See the API docs already posted by @moninom1

> [@](#):
>
> If a timeout occurs before a connection from a remote socket is accepted then NULL is returned.

---

<div class="post-metadata">

**Author:** ![taki](https://avatars.discourse-cdn.com/v4/letter/t/ccd318/32.png) [@taki](https://forums.freertos.org/u/taki)\
**Post date:** [June 21, 2024, 6:02am UTC](https://forums.freertos.org/t/freertos-accept-timeout/20788/5 "2024-06-21T06:02:39Z")

</div>

Thank you for your reply.

Is the following correct?  
If timeout occurs, do not come to the NG side

xConnectedSocket = FreeRTOS\_accept( xListeningSocket, &xClient, &xSize );  
//OK  
if(xConnectedSocket != 0){

}  
//NG  
else{

}

---

<div class="post-metadata">

**Author:** ![hs2](https://avatars.discourse-cdn.com/v4/letter/h/a4c791/32.png) [@hs2](https://forums.freertos.org/u/hs2)\
**Post date:** [June 21, 2024, 6:15am UTC](https://forums.freertos.org/t/freertos-accept-timeout/20788/6 "2024-06-21T06:15:44Z")

</div>

I don’t know what NG is, but your check of the return value is ok.  
In fact it’s the handle of/pointer to the accepted socket or `NULL` pointer.  
Although I’d use `NULL` in C-code or `nullptr` in C++ code rather than ‘0’ 😉

---

<div class="post-metadata">

**Author:** ![taki](https://avatars.discourse-cdn.com/v4/letter/t/ccd318/32.png) [@taki](https://forums.freertos.org/u/taki)\
**Post date:** [June 21, 2024, 6:39am UTC](https://forums.freertos.org/t/freertos-accept-timeout/20788/7 "2024-06-21T06:39:42Z")

</div>

Thank you for your reply.

If return value is ok,  
maybe there’s a mistake in my code

I will review the code

Thank you

---

<div class="post-metadata">

**Author:** ![Shub](https://avatars.discourse-cdn.com/v4/letter/s/6f9a4e/32.png) [@Shub](https://forums.freertos.org/u/Shub)\
**Post date:** [June 21, 2024, 9:56am UTC](https://forums.freertos.org/t/freertos-accept-timeout/20788/8 "2024-06-21T09:56:47Z")

</div>

hi @taki,  
These are the return values of FreeRTOS\_accept():

**Returns:**

If a connection from a remote socket is accepted and a new local socket is created to handle the accepted connection then a handle to the new socket is returned.

If xServerSocket is not a valid TCP socket then then FREERTOS\_INVALID\_SOCKET is returned.

If xServerSocket is not in the Listening state (see [FreeRTOS\_listen()](https://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/API/listen.html)) then FREERTOS\_INVALID\_SOCKET is returned.

If a timeout occurs before a connection from a remote socket is accepted then NULL is returned.

You can refer to the entire documentation at: [FreeRTOS\_accept](https://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/API/accept.html?_ga=2.20434424.1102677550.1718960178-647670286.1649955780)
