diff options
Diffstat (limited to 'mac/tclMacSock.c')
-rw-r--r-- | mac/tclMacSock.c | 32 |
1 files changed, 30 insertions, 2 deletions
diff --git a/mac/tclMacSock.c b/mac/tclMacSock.c index b36ae1d..17436da 100644 --- a/mac/tclMacSock.c +++ b/mac/tclMacSock.c @@ -8,7 +8,7 @@ * See the file "license.terms" for information on usage and redistribution * of this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tclMacSock.c,v 1.2 1998/09/14 18:40:06 stanton Exp $ + * RCS: @(#) $Id: tclMacSock.c,v 1.3 1999/04/15 22:38:47 stanton Exp $ */ #include "tclInt.h" @@ -82,6 +82,9 @@ typedef struct TcpState { rdsEntry rdsarray[5+1]; /* Array used when cleaning out recieve * buffers on a closing socket. */ Tcl_Channel channel; /* Channel associated with this socket. */ + int writeBufferSize; /* Size of buffer to hold data for + * asynchronous writes. */ + void *writeBuffer; /* Buffer for async write data. */ struct TcpState *nextPtr; /* The next socket on the global socket * list. */ } TcpState; @@ -1210,8 +1213,26 @@ TcpOutput( if (toWrite < amount) { amount = toWrite; } + + /* We need to copy the data, otherwise the caller may overwrite + * the buffer in the middle of our asynchronous call + */ + + if (amount > statePtr->writeBufferSize) { + /* + * need to grow write buffer + */ + + if (statePtr->writeBuffer != (void *) NULL) { + ckfree(statePtr->writeBuffer); + } + statePtr->writeBuffer = (void *) ckalloc(amount); + statePtr->writeBufferSize = amount; + } + memcpy(statePtr->writeBuffer, buf, amount); + statePtr->dataSegment[0].ptr = statePtr->writeBuffer; + statePtr->dataSegment[0].length = amount; - statePtr->dataSegment[0].ptr = buf; statePtr->dataSegment[1].length = 0; InitMacTCPParamBlock(&statePtr->pb, TCPSend); statePtr->pb.ioCompletion = completeUPP; @@ -1479,6 +1500,8 @@ NewSocketInfo( statePtr->watchMask = 0; statePtr->acceptProc = (Tcl_TcpAcceptProc *) NULL; statePtr->acceptProcData = (ClientData) NULL; + statePtr->writeBuffer = (void *) NULL; + statePtr->writeBufferSize = 0; statePtr->nextPtr = socketList; socketList = statePtr; return statePtr; @@ -1516,6 +1539,11 @@ FreeSocketInfo( } } } + + if (statePtr->writeBuffer != (void *) NULL) { + ckfree(statePtr->writeBuffer); + } + ckfree((char *) statePtr); } |