Thread: Assertion Failure

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    May 2004
    Posts
    215

    Assertion Failure

    Hey, im working on this code, and I keep getting an assertion failure.

    ws_fdr= fdopen(ws_sockfd,"r");
    ws_fdw= fdopen(ws_sockfd,"w");

    if you are wondering, ws_sockfd is an integer and equale to 1896 after going through this if statement:

    if ( (ws_sockfd = socket(AF_INET, SOCK_STREAM, 0)) < 0)
    err(WARN,"Wave_Server: socket connect error\n");

    please help.

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    What's the assertion you're getting, and what line is it in?

    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    Registered User
    Join Date
    May 2004
    Posts
    215
    I Get a debug assertion failure when the program is trying to execute either of the following statements:

    ws_fdr= fdopen(ws_sockfd,"r");
    ws_fdw= fdopen(ws_sockfd,"w");

    I have posted the code to the FUNCTION on this website, so I'll send you the link. The error occurs in between the lines of 90 and 100. You'll see it because its numbered in the side, so you'll know what line you are on. It's the same code. Anyways, heres the site, I hope someone can help me.


    http://sourcepost.sytes.net/sourcevi...ource_id=14603

  4. #4
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718
    What OS/compiler are you using?
    Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

    You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie

  5. #5
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Serves you right for using global variables. Seriously though, when hunting down pain in the ass problems, it actually helps if you provide all variable declarations, especially since they're being used in the lines in question.

    Quzah.
    Hope is the first step on the road to disappointment.

  6. #6
    Registered User
    Join Date
    May 2004
    Posts
    215
    I'm using MS Visual C++ 6.0. This code actually works on UNIX, and I am attempting to change this into a Windows program. I'm coding it in C. I have now posted the entire code on this website, and the errors are now between 00630 and 00640.

    Heres the site to see my code:

    http://sourcepost.sytes.net/sourcevi...ource_id=14614

    Please help.
    Thanks :-)

  7. #7
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    In Windows, a socket is not a file descriptor. To get a file descriptor from a socket you can use _open_osfhandle(). You must call _close() on the resulting file descriptor and closesocket() on the original socket when you are done.

  8. #8
    Registered User
    Join Date
    May 2004
    Posts
    215
    Can you give me an example with the code I have, because I'm kind of puzzled on how to do that.

    Thanks

  9. #9
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    Code:
      /* Get a file descriptor for the socket. */
      int fd_rd = _open_osfhandle(ws_sockfd, _O_RDONLY);
    
      /* Error handling */
      if (fd_rd == -1) exit(-1);
    
      /* Get a stream for the file descriptor. */
      ws_fdr = fdopen(fd_rd,"r");
    and cleanup:
    Code:
    /* Close stream */
    fclose(ws_fdr);
    
    /* Close file descriptor */
    _close(fd_rd);
    
    /* Close socket */
    closesocket(ws_sockfd);

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. File I/O Assertion Failure in VS2008
    By clegs in forum C Programming
    Replies: 5
    Last Post: 12-25-2008, 04:47 AM
  2. Debug Assertion failure problem
    By uldaman in forum C++ Programming
    Replies: 8
    Last Post: 01-21-2008, 02:22 AM
  3. debug assertion failure
    By talz13 in forum Windows Programming
    Replies: 2
    Last Post: 07-20-2004, 11:23 AM
  4. Assertion failure while creating window
    By roktsyntst in forum Windows Programming
    Replies: 0
    Last Post: 02-10-2003, 08:18 PM
  5. Assertion Failure
    By drdroid in forum Game Programming
    Replies: 9
    Last Post: 01-04-2003, 07:02 PM