Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 879679
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T11:58:21+00:00 2026-05-15T11:58:21+00:00

In some cases, I’d like to explicitly discard packets waiting on the socket with

  • 0

In some cases, I’d like to explicitly discard packets waiting on the socket with as little overhead as possible. It seems there’s no explicit “drop udp buffer” system call, but maybe I’m wrong?

The next best way would be probably to recv the packet to a temporary buffer and just drop it. It seems I can’t receive 0 bytes, since man says about recv: The return value will be 0 when the peer has performed an orderly shutdown. So 1 is the minimum in this case.

Is there any other way to handle this?

Just in case – this is not a premature optimisation. The only thing this server is doing is forwarding / dispatching the UDP packets in a specific way – although recv with len=1 won’t kill me, I’d rather just discard the whole queue in one go with some more specific function (hopefully lowering the latency).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T11:58:22+00:00Added an answer on May 15, 2026 at 11:58 am

    You can have the kernel discard your UDP packets by setting the UDP receive buffer to 0.

    int UdpBufSize = 0;
    socklen_t optlen = sizeof(UdpBufSize);
    setsockopt(socket, SOL_SOCKET, SO_RCVBUF, &UdpBufSize, optlen);
    

    Whenever you see fit to receive packets, you can then set the buffer to, for example, 4096 bytes.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

It seems that in some cases, if you end up with nested modalPopups wrapped
We are using Entity Framework 1.0. In some cases we need to explicitly open
It is possible to write a Regex which needs in some cases exponential running
I was using wsdlpull library for wsdl parser. But it seems for some cases
There are some cases when we include .cpp file instead of standard header file
it it possible that in some cases NEW returns some value, for example NULL,
There are editors better than dreamweaver in some cases but because most of them
I know that logically, there are some cases where NULL values make sense in
Using Control.Concurrent and forkIO, there are some cases that will leave the thread in
There are some cases we don't care about the Exception and just need to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.