added mio_dev_sck_setsockopt(), mio_dev_sck_getsockopt()

fixed the ssl part of the stateful socket writev method.
This commit is contained in:
hyung-hwan 2020-02-23 16:11:32 +00:00
parent 75887e4f74
commit d98397cd1f
4 changed files with 60 additions and 11 deletions

View File

@ -160,13 +160,18 @@ static void tcp_sck_on_disconnect (mio_dev_sck_t* tcp)
static void tcp_sck_on_connect (mio_dev_sck_t* tcp)
{
mio_bch_t buf1[128], buf2[128];
mio_bch_t k[50000];
mio_iovec_t iov[] =
{
{ "hello", 5 },
{ "world", 5 },
{ "mio test", 8 }
{ k, MIO_COUNTOF(k) },
{ "mio test", 8 },
{ k, MIO_COUNTOF(k) }
};
int i;
mio_skadtobcstr (tcp->mio, &tcp->localaddr, buf1, MIO_COUNTOF(buf1), MIO_SKAD_TO_BCSTR_ADDR | MIO_SKAD_TO_BCSTR_PORT);
mio_skadtobcstr (tcp->mio, &tcp->remoteaddr, buf2, MIO_COUNTOF(buf2), MIO_SKAD_TO_BCSTR_ADDR | MIO_SKAD_TO_BCSTR_PORT);
@ -179,6 +184,15 @@ static void tcp_sck_on_connect (mio_dev_sck_t* tcp)
MIO_INFO3 (tcp->mio, "DEVICE accepted client device... .LOCAL %hs REMOTE %hs SCK: %d\n", buf1, buf2, tcp->sck);
}
for (i = 0; i < MIO_COUNTOF(k); i++) k[i] = 'A' + (i % 26);
/*
{
int sndbuf = 2000;
mio_dev_sck_setsockopt(tcp, SOL_SOCKET, SO_SNDBUF, &sndbuf, MIO_SIZEOF(sndbuf));
}
*/
if (mio_dev_sck_writev(tcp, iov, MIO_COUNTOF(iov), MIO_NULL, MIO_NULL) <= -1)
{
mio_dev_sck_halt (tcp);

View File

@ -514,6 +514,21 @@ static MIO_INLINE int mio_dev_sck_timedread (mio_dev_sck_t* sck, int enabled, mi
MIO_EXPORT int mio_dev_sck_setsockopt (
mio_dev_sck_t* dev,
int level,
int optname,
void* optval,
mio_scklen_t optlen
);
MIO_EXPORT int mio_dev_sck_getsockopt (
mio_dev_sck_t* dev,
int level,
int optname,
void* optval,
mio_scklen_t* optlen
);
MIO_EXPORT mio_uint16_t mio_checksumip (
const void* hdr,

View File

@ -1331,7 +1331,7 @@ static int __dev_writev (mio_dev_t* dev, mio_iovec_t* iov, mio_iolen_t iovcnt, c
backup_index = index;
}
iov[index].iov_ptr = (void*)((mio_uint8_t*)iov[index].iov_ptr + x);
iov[index].iov_ptr = (void*)((mio_uint8_t*)iov[index].iov_ptr + dcnt);
iov[index].iov_len -= dcnt;
}
while (1);

View File

@ -554,10 +554,11 @@ static int dev_sck_writev_stateful (mio_dev_t* dev, const mio_iovec_t* iov, mio_
mio_t* mio = dev->mio;
mio_dev_sck_t* rdev = (mio_dev_sck_t*)dev;
#if 0 && defined(USE_SSL)
#if defined(USE_SSL)
if (rdev->ssl)
{
int x;
mio_iolen_t i, nwritten;
if (*iovcnt <= 0)
{
@ -571,16 +572,24 @@ static int dev_sck_writev_stateful (mio_dev_t* dev, const mio_iovec_t* iov, mio_
return 1;
}
x = SSL_write((SSL*)rdev->ssl, data, *len);
if (x <= -1)
nwritten = 0;
for (i = 0; i < *iovcnt; i++)
{
int err = SSL_get_error ((SSL*)rdev->ssl, x);
if (err == SSL_ERROR_WANT_READ || err == SSL_ERROR_WANT_WRITE) return 0;
set_ssl_error (mio, err);
return -1;
/* no SSL_writev. invoke multiple calls to SSL_write().
* since the write function is for the stateful connection,
* mutiple calls shouldn't really matter */
x = SSL_write((SSL*)rdev->ssl, iov[i].iov_ptr, iov[i].iov_len);
if (x <= -1)
{
int err = SSL_get_error ((SSL*)rdev->ssl, x);
if (err == SSL_ERROR_WANT_READ || err == SSL_ERROR_WANT_WRITE) return 0;
set_ssl_error (mio, err);
return -1;
}
nwritten += x;
}
*len = x;
*iovcnt = nwritten;
}
else
{
@ -624,7 +633,7 @@ static int dev_sck_writev_stateful (mio_dev_t* dev, const mio_iovec_t* iov, mio_
}
*iovcnt = x;
#if 0 && defined(USE_SSL)
#if defined(USE_SSL)
}
#endif
return 1;
@ -1729,6 +1738,17 @@ int mio_dev_sck_timedwritev (mio_dev_sck_t* dev, mio_iovec_t* iov, mio_iolen_t i
}
/* ========================================================================= */
int mio_dev_sck_setsockopt (mio_dev_sck_t* dev, int level, int optname, void* optval, mio_scklen_t optlen)
{
return setsockopt(dev->sck, level, optname, optval, optlen);
}
int mio_dev_sck_getsockopt (mio_dev_sck_t* dev, int level, int optname, void* optval, mio_scklen_t* optlen)
{
return getsockopt(dev->sck, level, optname, optval, optlen);
}
/* ========================================================================= */
mio_uint16_t mio_checksumip (const void* hdr, mio_oow_t len)