OS_Error HTTPClientSocket::SendV(iovec* inVec, UInt32 inNumVecs) { // // Bring up the POST connection if we need to if (fPostSocket == NULL) fPostSocket = NEW TCPSocket(NULL, fSocketType); if (!fPostSocket->IsConnected()) { #if CLIENT_SOCKET_DEBUG qtss_printf("HTTPClientSocket::Send: Sending POST\n"); #endif qtss_sprintf(fSendBuffer.Ptr, "POST %s HTTP/1.0\r\nX-SessionCookie: %" _U32BITARG_ "\r\nAccept: application/x-rtsp-rtp-interleaved\r\nUser-Agent: QTSS/2.0\r\n\r\n", fURL.Ptr, fCookie); fSendBuffer.Len = ::strlen(fSendBuffer.Ptr); this->encodeVec(inVec, inNumVecs); } OS_Error theErr = this->Connect(fPostSocket); if (theErr != OS_NoErr) return theErr; // // If we have nothing to send currently, this should be a new message, in which case // we can encode it and send it if (fSendBuffer.Len == 0) this->encodeVec(inVec, inNumVecs); #if CLIENT_SOCKET_DEBUG //qtss_printf("HTTPClientSocket::Send: Sending data\n"); #endif return this->SendSendBuffer(fPostSocket); }
/* * FUNCTION: Opens a connection file object * ARGUMENTS: * Request = Pointer to TDI request structure for this request * ClientContext = Pointer to client context information * RETURNS: * Status of operation */ NTSTATUS FileOpenConnection( PTDI_REQUEST Request, PVOID ClientContext) { NTSTATUS Status; PCONNECTION_ENDPOINT Connection; TI_DbgPrint(MID_TRACE, ("Called.\n")); Connection = TCPAllocateConnectionEndpoint( ClientContext ); if( !Connection ) return STATUS_NO_MEMORY; Status = TCPSocket( Connection, AF_INET, SOCK_STREAM, IPPROTO_TCP ); if( !NT_SUCCESS(Status) ) { DereferenceObject( Connection ); return Status; } /* Return connection endpoint file object */ Request->Handle.ConnectionContext = Connection; TI_DbgPrint(MAX_TRACE, ("Leaving.\n")); return STATUS_SUCCESS; }
bool Socket::accept( Socket& sock ) { SocketDesc fd = ::accept( getFD(), NULL, 0 ); if( fd == INVALIDSOCKET ) return false; sock = TCPSocket( fd ); return true; }
TCPSocket ConnectionListener::blocking_wait(){ sockaddr_storage client_sockaddr; socklen_t client_sockaddr_size = sizeof(client_sockaddr); int client_sockfd = accept(server_sockfd, reinterpret_cast<sockaddr*>(&client_sockaddr), &client_sockaddr_size); if(client_sockfd == -1){ //TODO : report about invalid client socket } return TCPSocket(client_sockfd); }
ProteinClient::ProteinClient(const char* serverName,int serverPort) :pipe(new ClientServerPipe(TCPSocket(serverName,serverPort))) { /* Send connect request message: */ pipe->writeMessage(ClientServerPipe::CONNECT_REQUEST); /* Wait for connect reply message: */ if(!pipe->getSocket().waitForData(10,0,false)) throw ProtocolError("ProteinClient: Server timed out during connection initialization"); ClientServerPipe::MessageIdType reply=pipe->readMessage(); if(reply==ClientServerPipe::NACK) throw ProtocolWarning("ProteinClient: Server refused connection"); else if(reply!=ClientServerPipe::CONNECT_REPLY) throw ProtocolError("ProteinClient: Mismatching message during connection initialization"); }
void HTTPSessionInterface::SnarfInputSocket( HTTPSessionInterface* fromRTSPSession ) { Assert( fromRTSPSession != NULL ); Assert( fromRTSPSession->fOutputSocketP != NULL ); fInputStream.SnarfRetreat( fromRTSPSession->fInputStream ); if (fInputSocketP == fOutputSocketP) fInputSocketP = NEW TCPSocket( this, Socket::kNonBlockingSocketType ); else fInputSocketP->Cleanup(); // if this is a socket replacing an old socket, we need // to make sure the file descriptor gets closed fInputSocketP->SnarfSocket( fromRTSPSession->fSocket ); // fInputStream, meet your new input socket fInputStream.AttachToSocket( fInputSocketP ); }
NTSTATUS DispTdiListen( PIRP Irp) /* * FUNCTION: TDI_LISTEN handler * ARGUMENTS: * Irp = Pointer to an I/O request packet * RETURNS: * Status of operation */ { PCONNECTION_ENDPOINT Connection; PTDI_REQUEST_KERNEL Parameters; PTRANSPORT_CONTEXT TranContext; PIO_STACK_LOCATION IrpSp; NTSTATUS Status = STATUS_SUCCESS; KIRQL OldIrql; TI_DbgPrint(DEBUG_IRP, ("Called.\n")); IrpSp = IoGetCurrentIrpStackLocation(Irp); /* Get associated connection endpoint file object. Quit if none exists */ TranContext = IrpSp->FileObject->FsContext; if (TranContext == NULL) { TI_DbgPrint(MID_TRACE, ("Bad transport context.\n")); Status = STATUS_INVALID_PARAMETER; goto done; } Connection = (PCONNECTION_ENDPOINT)TranContext->Handle.ConnectionContext; if (Connection == NULL) { TI_DbgPrint(MID_TRACE, ("No connection endpoint file object.\n")); Status = STATUS_INVALID_PARAMETER; goto done; } Parameters = (PTDI_REQUEST_KERNEL)&IrpSp->Parameters; Status = DispPrepareIrpForCancel (TranContext->Handle.ConnectionContext, Irp, (PDRIVER_CANCEL)DispCancelListenRequest); LockObject(Connection, &OldIrql); if (Connection->AddressFile == NULL) { TI_DbgPrint(MID_TRACE, ("No associated address file\n")); UnlockObject(Connection, OldIrql); Status = STATUS_INVALID_PARAMETER; goto done; } LockObjectAtDpcLevel(Connection->AddressFile); /* Listening will require us to create a listening socket and store it in * the address file. It will be signalled, and attempt to complete an irp * when a new connection arrives. */ /* The important thing to note here is that the irp we'll complete belongs * to the socket to be accepted onto, not the listener */ if( NT_SUCCESS(Status) && !Connection->AddressFile->Listener ) { Connection->AddressFile->Listener = TCPAllocateConnectionEndpoint( NULL ); if( !Connection->AddressFile->Listener ) Status = STATUS_NO_MEMORY; if( NT_SUCCESS(Status) ) { ReferenceObject(Connection->AddressFile); Connection->AddressFile->Listener->AddressFile = Connection->AddressFile; Status = TCPSocket( Connection->AddressFile->Listener, Connection->AddressFile->Family, SOCK_STREAM, Connection->AddressFile->Protocol ); } if( NT_SUCCESS(Status) ) { ReferenceObject(Connection->AddressFile->Listener); Status = TCPListen( Connection->AddressFile->Listener, 1024 ); /* BACKLOG */ } } if( NT_SUCCESS(Status) ) { Status = TCPAccept ( (PTDI_REQUEST)Parameters, Connection->AddressFile->Listener, Connection, DispDataRequestComplete, Irp ); } UnlockObjectFromDpcLevel(Connection->AddressFile); UnlockObject(Connection, OldIrql); done: if (Status != STATUS_PENDING) { DispDataRequestComplete(Irp, Status, 0); } else IoMarkIrpPending(Irp); TI_DbgPrint(MID_TRACE,("Leaving %x\n", Status)); return Status; }