--#--
Readin', writin' and server response
--#--
We need to make minor changes to the writeToSocket, readn and
printSocketResponse functions. Primarily, we'll replace any
reference to the int socket handle with a reference to the SSL
structure, and calls to read and write with SSL_read and SSL_write.
int writeToSSLSocket(SSL *ssl, char *request) {
int bytesWritten;
bytesWritten = SSL_write(ssl, request, strlen(request));
return bytesWritten;
}
int readn(SSL *ssl, char *buf, int n) {
unsigned char *p;
int i;
int nread;
p = (unsigned char *)buf;
i = 0;
while (i < n) {
nread = SSL_read(ssl, p, n-1);
if (nread <=0) return i;
p += nread;
i += nread;
}
return i;
}
void printSSLServerResponse(SSL *ssl) {
int bytesRead;
int readsize = 4096;
char buf[readSize + 2];
memset(buf, 0, sizeof(buf));
while (bytesRead = readn(ssl, buf, readSize)) {
printf(buf);
memset(buf, 0, sizeof(buf));
}
}
Put this and the rest of what was in sockets.c and name it ssl_sockets.c