News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

WSARecv

Started by Rage9, February 28, 2007, 11:32:26 PM

Previous topic - Next topic

Rage9

Been working on this problem for more hours than I'd like to admit.

It seems to me it will be an easy-fix but my brain is fried over this issue.  :dazzled:

WSARecv keeps failing and WSAGetLastError keeps returning:

WSAEFAULT
10014    

Bad address.
    The system detected an invalid pointer address in attempting to use a pointer argument of a call. This error occurs if an application passes an invalid pointer value, or if the length of the buffer is too small. For instance, if the length of an argument, which is a sockaddr structure, is smaller than the sizeof(sockaddr).



WSABUF STRUCT
  len    DWORD   ?
  buf   DWORD   ?
WSABUF ENDS

AcceptConnection Proc uses ebx

       local   dwFlags:DWORD,
dwBytes:DWORD,
                wbuf:WSABUF,
ol:OVERLAPPED

;associating with IOCP stuff

                mov dwFlags, 0
        mov dwBytes, 0

                invoke WSARecv, [ebx].hSocket, addr wbuf, 1,  addr dwBytes,  dwFlags,  addr ol, NULL




Return Values

If no error occurs and the receive operation has completed immediately, WSARecv returns zero. Note that in this case, the completion routine will have already been scheduled, and to be called once the calling thread is in the alertable state. Otherwise, a value of SOCKET_ERROR is returned, and a specific error code may be retrieved by calling WSAGetLastError. The error code WSA_IO_PENDING indicates that the overlapped operation has been successfully initiated and that completion will be indicated at a later time. Any other error code indicates that the overlapped operation was not successfully initiated and no completion indication will occur.

In this case WSAEFAULT.  Driving me nuts - thanks in advance.

Tedd

Simple check first: what's the value of ebx?

(Also, I'd give NULL for lpOverlapped if you're not using it; if you are then lpCompletion shouldn't be null.)
No snowflake in an avalanche feels responsible.

japheth


at least check how OVERLAPPED has to be initialized. It isn't allowed to hold random values.

Rage9

It has been pointed out to me that my problem lies in the fact that the structure is defined incorrectly.

Ex found here: http://msdn2.microsoft.com/en-us/library/ms741542.aspx

Most noticeably seen:

WSABUF DataBuf;
char SendBuf[1024] = "Test data to send.";
int BufLen = 1024;

...

DataBuf.len = BufLen;
DataBuf.buf = SendBuf;


As seen .buf is an actual array hence of characters and .len is the actual length of the buffer.

I change

WSABUF STRUCT
  len    DWORD  ?
  buf   DWORD   ?
WSABUF ENDS


To

WSABUF STRUCT
  len    db 256 DUP(?)
  buf   DWORD   ?
WSABUF ENDS


Now when trying to compile it, the compiler process just hangs.

Thoughts?

PBrennick

Probably because you are overwriting other parts of data. I think it should be:


WSABUF STRUCT
  buf    db 256 DUP(?)
  len   DWORD   ?
WSABUF ENDS


Paul
The GeneSys Project is available from:
The Repository or My crappy website

MichaelW

Rage9,


typedef struct _WSABUF {
    u_long      len;     /* the length of the buffer */
    char FAR *  buf;     /* the pointer to the buffer */
} WSABUF, FAR * LPWSABUF;


A "u_long" is a DWORD and a "char FAR *" is a DWORD.
eschew obfuscation

edike123

Rage 9,

I had the same problem, it can also occur if setsockopt is not invoked on [ebx].hSocket.

check out the following post: http://www.masm32.com/board/index.php?topic=15547.0


dedndave

change this...
WSABUF STRUCT
  len   db 256 DUP(?)
  buf   DWORD   ?
WSABUF ENDS

to this...
WSABUF STRUCT
  len   DWORD ?
  buf   db 256 DUP(?)
WSABUF ENDS

or...
WSABUF STRUCT
  len   dd ?
  buf   db 256 DUP(?)
WSABUF ENDS


edlike.....
this thread is 3 years old   :P

edike123

Quote from: dedndave on December 07, 2010, 04:04:58 PM

edlike.....
this thread is 3 years old   :P
dedndave,

I know that but I still think it is worth responding, because googling  "WSARecv error" easily redirects to this post, so maybe others having similar problems will be able to find solutions more efficiently. (sorry for being off topic)

dedndave

no problem   :P

sometimes, people post without realizing the thread is old