Clarify the use of `socketfd'

This commit is contained in:
styan 2020-05-01 04:38:28 +00:00
parent a96621e3fd
commit bf54ebef7e
1 changed files with 22 additions and 2 deletions

View File

@ -130,6 +130,7 @@ struct gemini {
size_t metalen; /* Length of `meta' */
int flags; /* Configuration flags */
int maxredirects; /* Default 5 */
int socketfd; /* The socket to use */
short status; /* Response STATUS */
short port; /* Default port */
};
@ -238,11 +239,28 @@ structure, or a NULL on a failure.
and
.Fn gemini_connect_query
returns a 0 on success and a -1 on an error.
They can also return
.Dv TLS_WANT_POLLIN
and
.Dv TLS_WANT_POLLOUT
if
.Fa socketfd
is set to a non-blocking file-descriptor, even if they do it is safe to
call
.Fn gemini_read
at this point.
.Pp
.Fn gemini_read
returns a -1 on an error, otherwise it returns the amount of data
read into the buffer, with 0 only being returned when there is nothing
left to read after successfully reading the response header.
It can also return
.Dv TLS_WANT_POLLIN
and
.Dv TLS_WANT_POLLOUT
if
.Fa socketfd
is set to a non-blocking file-descriptor.
.Sh EXAMPLES
The following example shows how you initialize various values:
.Bd -literal -offset indent -compact
@ -281,12 +299,14 @@ while ((url = get_url()) != NULL) {
switch (gemini->status / 10) {
...
case 3:
if (yesno("Redirected to \"%s\" [Y/n]?", gemini->meta))
if (yesno("Redirected to \\"%s\\" [Y/n]?",
gemini->meta))
prepend_url(gemini->meta);
break;
...
default:
warn("Bad status %02hd: %s", gemini->status, g->meta);
warn("Bad status %02hd: %s", gemini->status,
gemini->meta);
break;
}
gemini_reset(gemini);