Bugzilla bug #34920: test PR_EmulateSendFile.

This commit is contained in:
wtc%netscape.com 2000-05-26 22:08:29 +00:00
parent 2a97b66a80
commit edc8cd854f

View File

@ -132,6 +132,10 @@ static PRInt32 udp_datagram_size = UDP_DGRAM_SIZE;
static PRInt32 thread_count;
PRUint16 server_domain = PR_AF_INET, client_domain = PR_AF_INET;
/* an I/O layer that uses the emulated senfile method */
static PRDescIdentity emuSendFileIdentity;
static PRIOMethods emuSendFileMethods;
int failed_already=0;
typedef struct buffer {
char data[BUF_DATA_SIZE];
@ -160,6 +164,31 @@ typedef struct Client_Param {
PRInt32 udp_connect; /* if set clients connect udp sockets */
} Client_Param;
/* the sendfile method in emuSendFileMethods */
static PRInt32 PR_CALLBACK
emu_SendFile(PRFileDesc *sd, PRSendFileData *sfd,
PRTransmitFileFlags flags, PRIntervalTime timeout)
{
return PR_EmulateSendFile(sd, sfd, flags, timeout);
}
/* the transmitfile method in emuSendFileMethods */
static PRInt32 PR_CALLBACK
emu_TransmitFile(PRFileDesc *sd, PRFileDesc *fd, const void *headers,
PRInt32 hlen, PRTransmitFileFlags flags, PRIntervalTime timeout)
{
PRSendFileData sfd;
sfd.fd = fd;
sfd.file_offset = 0;
sfd.file_nbytes = 0;
sfd.header = headers;
sfd.hlen = hlen;
sfd.trailer = NULL;
sfd.tlen = 0;
return emu_SendFile(sd, &sfd, flags, timeout);
}
/*
* readn
* read data from sockfd into buf
@ -1762,6 +1791,24 @@ TransmitFile_Server(void *arg)
failed_already=1;
goto exit;
}
/* test both regular and emulated PR_SendFile */
if (i%2) {
PRFileDesc *layer = PR_CreateIOLayerStub(
emuSendFileIdentity, &emuSendFileMethods);
if (layer == NULL) {
fprintf(stderr,
"prsocket_test: ERROR - PR_CreateIOLayerStub failed\n");
failed_already=1;
goto exit;
}
if (PR_PushIOLayer(newsockfd, PR_TOP_IO_LAYER, layer)
== PR_FAILURE) {
fprintf(stderr,
"prsocket_test: ERROR - PR_PushIOLayer failed\n");
failed_already=1;
goto exit;
}
}
scp = PR_NEW(Serve_Client_Param);
if (scp == NULL) {
fprintf(stderr,"prsocket_test: PR_NEW failed\n");
@ -2161,6 +2208,12 @@ main(int argc, char **argv)
SetupMacPrintfLog("socket.log");
#endif
PR_SetConcurrency(4);
emuSendFileIdentity = PR_GetUniqueIdentity("Emulated SendFile");
emuSendFileMethods = *PR_GetDefaultIOMethods();
emuSendFileMethods.transmitfile = emu_TransmitFile;
emuSendFileMethods.sendfile = emu_SendFile;
/*
* run client-server test with TCP, Ipv4-Ipv4
*/