PORT_Assert( ssl_HaveXmitBufLock(ss) );
PORT_Assert( ss->opt.noLocks || ssl_HaveXmitBufLock(ss) );
ssl2_SendStream(sslSocket *ss, const PRUint8 *in, PRInt32 len, PRInt32 flags){    PRUint8       *  out;    int              rv;    int              count	= 0;    int              amount;    PRUint8          macLen;    int              nout;    int              buflen;    PORT_Assert( ssl_HaveXmitBufLock(ss) );    SSL_TRC(10, ("%d: SSL[%d]: sending %d bytes using stream cipher",		 SSL_GETPID(), ss->fd, len));    PRINT_BUF(50, (ss, "clear data:", (PRUint8*) in, len));    while (len) {	ssl_GetSpecReadLock(ss);  /*************************************/	macLen = ss->sec.hash->length;	amount = PR_MIN( len, MAX_STREAM_CYPHER_LEN );	buflen = amount + 2 + macLen;	if (buflen > ss->sec.writeBuf.space) {	    rv = sslBuffer_Grow(&ss->sec.writeBuf, buflen);	    if (rv != SECSuccess) {		goto loser;	    }	}	out    = ss->sec.writeBuf.buf;	nout   = amount + macLen;	out[0] = 0x80 | MSB(nout);	out[1] = LSB(nout);	/* Calculate MAC */	rv = ssl2_CalcMAC(out+2, 		/* put MAC here */	                  &ss->sec, 		          in, amount, 		/* input addr & length */			  0); 			/* no padding */	if (rv != SECSuccess) 	    goto loser;	/* Encrypt MAC */	rv = (*ss->sec.enc)(ss->sec.writecx, out+2, &nout, macLen, out+2, macLen);	if (rv) goto loser;	/* Encrypt data from caller */	rv = (*ss->sec.enc)(ss->sec.writecx, out+2+macLen, &nout, amount, in, amount);	if (rv) goto loser;	ssl_ReleaseSpecReadLock(ss);  /*************************************/	PRINT_BUF(50, (ss, "encrypted data:", out, buflen));	rv = ssl_DefSend(ss, out, buflen, flags & ~ssl_SEND_FLAG_MASK);	if (rv < 0) {	    if (PORT_GetError() == PR_WOULD_BLOCK_ERROR) {		SSL_TRC(50, ("%d: SSL[%d]: send stream would block, "			     "saving data", SSL_GETPID(), ss->fd));		rv = 0;	    } else {		SSL_TRC(10, ("%d: SSL[%d]: send stream error %d",			     SSL_GETPID(), ss->fd, PORT_GetError()));		/* Return short write if some data already went out... */		if (count == 0)		    count = rv;		goto done;	    }	}	if ((unsigned)rv < buflen) {	    /* Short write.  Save the data and return. */	    if (ssl_SaveWriteData(ss, &ss->pendingBuf, out + rv,				  buflen - rv) == SECFailure) {		count = SECFailure;	    } else {	    	count += amount;		ss->sec.sendSequence++;	    }	    goto done;	}	ss->sec.sendSequence++;	in    += amount;	count += amount;	len   -= amount;    }done:    return count;loser:    ssl_ReleaseSpecReadLock(ss);    return SECFailure;}