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

  • SEARCH
  • Home
  • 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 204875
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T17:30:23+00:00 2026-05-11T17:30:23+00:00

I’ve got an application using sockets (which I did not write, so bear with

  • 0

I’ve got an application using sockets (which I did not write, so bear with me) and when I try to close a socket, closesocket() fails with error WSAEOPNOTSUPP and the socket sticks around…as in, it is not fully deleted.

The socket is created as follows:

bool Socket::CreateConnection()
{
   int error;
   struct addrinfo hints;
   struct addrinfo *list = NULL;

   memset(&hints, 0, sizeof(hints));
   hints.ai_family = AF_INET;
   hints.ai_socktype = SOCK_STREAM;
   hints.ai_protocol = IPPROTO_TCP;

   error = getaddrinfo(socketAddress.c_str(), socketPort.c_str(), &hints, &list);
   if (error)
   {
      Log().RecordError("Unable to initialize connection to server", WSAGetLastError(), EventTypeError);
   }

   for (struct addrinfo *ptr = list; ptr != NULL; ptr = ptr->ai_next)
   {
      connection = socket(ptr->ai_family, ptr->ai_socktype, ptr->ai_protocol);
      if (connection == INVALID_SOCKET)
      {
         Log().RecordError("Unable to initialize socket connection", WSAGetLastError(), EventTypeError);
         break;
      }

      error = connect(connection, ptr->ai_addr, (int)ptr->ai_addrlen);
      if (error == SOCKET_ERROR)
      {
         closesocket(connection);
         connection = INVALID_SOCKET;
         continue;
      }
      break;
   }

   freeaddrinfo(list);

   return connection != INVALID_SOCKET;
}

And the destructor for the class:

Socket::~Socket()
{
   int error;

   if (connection != INVALID_SOCKET)
   {
      continueReading = false;

      error = shutdown(connection, SD_SEND);
      if (error != SOCKET_ERROR)
      {
         /* Finish any necessary receives to politely close the socket */
         int length;
         do
         {
            char buffer[1024];
            length = recv(connection, buffer, sizeof(buffer)/sizeof(*buffer), MSG_WAITALL);
         } while (length > 0);
      }
      else
      {
         Log().RecordError("Error shutting down connection to server", WSAGetLastError(), EventTypeError);
      }

      closesocket(connection);  //Fails HERE
      int wsa_err = WSAGetLastError();
      if(wsa_err)
          Log().RecordError("closesocket() error", wsa_err, EventTypeError);
   }

   if (winsockInitialized)
   {
      WSACleanup();
   }
}

Anyone have a clue why this would happen??

  • 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-11T17:30:23+00:00Added an answer on May 11, 2026 at 5:30 pm

    You’re not checking the return code on closesocket(), which means that WSAGetLastError() may or may not be related to the closesocket operation.

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

Sidebar

Ask A Question

Stats

  • Questions 105k
  • Answers 105k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer using twoway binding should help I guess {Binding ..., Path=Text,… May 11, 2026 at 8:40 pm
  • Editorial Team
    Editorial Team added an answer One approach you could try is to use ffmpeg to… May 11, 2026 at 8:40 pm
  • Editorial Team
    Editorial Team added an answer Windows Vista is letting you create the directory but it… May 11, 2026 at 8:40 pm

Related Questions

I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I am currently running into a problem where an element is coming back from
Seemingly simple, but I cannot find anything relevant on the web. What is the
Configuring TinyMCE to allow for tags, based on a customer requirement. My config is
Is it possible to replace javascript w/ HTML if JavaScript is not enabled on

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.