p=wb->buf;
if (!clear && !create_empty_fragment && !s->s3->empty_fragment_done) {  prefix_len = do_ssl3_write(s, type, buf, 0, 1); if (prefix_len <= 0) goto err;  if (s->s3->wbuf.len < prefix_len + SSL3_RT_MAX_PACKET_SIZE) {  SSLerr(SSL_F_DO_SSL3_WRITE, ERR_R_INTERNAL_ERROR); goto err; } }  s->s3->empty_fragment_done = 1; }  p = wb->buf + prefix_len;
static int do_ssl3_write(SSL *s, int type, const unsigned char *buf,			 unsigned int len)	{	unsigned char *p,*plen;	int i,mac_size,clear=0;	SSL3_RECORD *wr;	SSL3_BUFFER *wb;	SSL_SESSION *sess;	/* first check is there is a SSL3_RECORD still being written	 * out.  This will happen with non blocking IO */	if (s->s3->wbuf.left != 0)		return(ssl3_write_pending(s,type,buf,len));	/* If we have an alert to send, lets send it */	if (s->s3->alert_dispatch)		{		i=ssl3_dispatch_alert(s);		if (i <= 0)			return(i);		/* if it went, fall through and send more stuff */		}	if (len == 0) return(len);	wr= &(s->s3->wrec);	wb= &(s->s3->wbuf);	sess=s->session;	if (	(sess == NULL) ||		(s->enc_write_ctx == NULL) ||		(s->write_hash == NULL))		clear=1;	if (clear)		mac_size=0;	else		mac_size=EVP_MD_size(s->write_hash);	p=wb->buf;	/* write the header */	*(p++)=type&0xff;	wr->type=type;	*(p++)=(s->version>>8);	*(p++)=s->version&0xff;	/* record where we are to write out packet length */	plen=p; 	p+=2;	/* lets setup the record stuff. */	wr->data=p;	wr->length=(int)len;	wr->input=(unsigned char *)buf;	/* we now 'read' from wr->input, wr->length bytes into	 * wr->data */	/* first we compress */	if (s->compress != NULL)		{		if (!do_compress(s))			{			SSLerr(SSL_F_DO_SSL3_WRITE,SSL_R_COMPRESSION_FAILURE);			goto err;			}		}	else		{		memcpy(wr->data,wr->input,wr->length);		wr->input=wr->data;		}	/* we should still have the output to wr->data and the input	 * from wr->input.  Length should be wr->length.	 * wr->data still points in the wb->buf */	if (mac_size != 0)		{		s->method->ssl3_enc->mac(s,&(p[wr->length]),1);		wr->length+=mac_size;		wr->input=p;		wr->data=p;		}	/* ssl3_enc can only have an error on read */	s->method->ssl3_enc->enc(s,1);	/* record length after mac and block padding */	s2n(wr->length,plen);	/* we should now have	 * wr->data pointing to the encrypted data, which is	 * wr->length long */	wr->type=type; /* not needed but helps for debugging */	wr->length+=SSL3_RT_HEADER_LENGTH;	/* Now lets setup wb */	wb->left=wr->length;	wb->offset=0;	s->s3->wpend_tot=len;	s->s3->wpend_buf=buf;	s->s3->wpend_type=type;	s->s3->wpend_ret=len;	/* we now just need to write the buffer */	return(ssl3_write_pending(s,type,buf,len));err:	return(-1);	}