Posso usare SetBuffer con SocketAsyncEventArgs bene.Come utilizzare BufferList con SocketAsyncEventArgs e non ottenere SocketError InvalidArgument?
Se provo a utilizzare BufferList (dopo aver eseguito SetBuffer (null, 0, 0)) ottengo sempre e immediatamente SocketError InvalidArgument (10022) quando eseguo SendAsync sul socket.
Non ci sono esempi o documentazione su come usare BufferList e quello che sto facendo ha senso (per me comunque).
Qualcuno può indicare un programma di esempio o uno snippet di codice?
Sto strappando i capelli su questo e non hanno molto lasciato ...
Qui è fondamentalmente quello che sto facendo (e è SocketAsyncEventArgs e lSocket è lo stesso socket che uso per SetBuffer che funziona)
// null the buffer since we will use a buffer list
e.SetBuffer(null, 0, 0);
// create a bufferlist
e.BufferList = new List<ArraySegment<byte>>();
// create the bufferlist with the network header and the response bytes
e.BufferList.Add(new ArraySegment<byte>(lTxBytes)); // add the 4 character total length
e.BufferList.Add(new ArraySegment<byte>(Encoding.ASCII.GetBytes(lTx.Identity))); // echo back the incoming sequence number
e.BufferList.Add(new ArraySegment<byte>(Encoding.ASCII.GetBytes(lResponse)));
// *** the SendAsync always completes IMMEDIATELY (returns false) gets SocketError InvalidArgument (10022)
if (lSocket.SendAsync(e) == false)
{
// data was already sent back to the client.
AppSupport.WriteLog(LogLevel.Flow, "ProcessReceive had SendAsync complete synchronously (bytes transferred {0}).", e.BytesTransferred);
ProcessSend(e);
}
Hai una migliore possibilità di ottenere risposta per la tua domanda se la tagghi con la lingua che usi. –
Tutti i segmenti di array devono far parte dello stesso array di byte fisici? Se questo è il caso, renderebbe BufferList abbastanza inutile. Qualcuno ha usato BufferList con successo? – Dave
Qualcuno ha qualche idea qui? – Dave