mirror of
https://github.com/nginx/nginx.git
synced 2025-02-25 18:55:26 -06:00
Stream: UDP proxy.
This commit is contained in:
@@ -23,6 +23,7 @@ static ngx_os_io_t ngx_darwin_io = {
|
||||
ngx_readv_chain,
|
||||
ngx_udp_unix_recv,
|
||||
ngx_unix_send,
|
||||
ngx_udp_unix_send,
|
||||
#if (NGX_HAVE_SENDFILE)
|
||||
ngx_darwin_sendfile_chain,
|
||||
NGX_IO_SENDFILE
|
||||
|
||||
@@ -32,6 +32,7 @@ static ngx_os_io_t ngx_freebsd_io = {
|
||||
ngx_readv_chain,
|
||||
ngx_udp_unix_recv,
|
||||
ngx_unix_send,
|
||||
ngx_udp_unix_send,
|
||||
#if (NGX_HAVE_SENDFILE)
|
||||
ngx_freebsd_sendfile_chain,
|
||||
NGX_IO_SENDFILE
|
||||
|
||||
@@ -18,6 +18,7 @@ static ngx_os_io_t ngx_linux_io = {
|
||||
ngx_readv_chain,
|
||||
ngx_udp_unix_recv,
|
||||
ngx_unix_send,
|
||||
ngx_udp_unix_send,
|
||||
#if (NGX_HAVE_SENDFILE)
|
||||
ngx_linux_sendfile_chain,
|
||||
NGX_IO_SENDFILE
|
||||
|
||||
@@ -28,6 +28,7 @@ typedef struct {
|
||||
ngx_recv_chain_pt recv_chain;
|
||||
ngx_recv_pt udp_recv;
|
||||
ngx_send_pt send;
|
||||
ngx_send_pt udp_send;
|
||||
ngx_send_chain_pt send_chain;
|
||||
ngx_uint_t flags;
|
||||
} ngx_os_io_t;
|
||||
@@ -47,6 +48,7 @@ ssize_t ngx_udp_unix_recv(ngx_connection_t *c, u_char *buf, size_t size);
|
||||
ssize_t ngx_unix_send(ngx_connection_t *c, u_char *buf, size_t size);
|
||||
ngx_chain_t *ngx_writev_chain(ngx_connection_t *c, ngx_chain_t *in,
|
||||
off_t limit);
|
||||
ssize_t ngx_udp_unix_send(ngx_connection_t *c, u_char *buf, size_t size);
|
||||
|
||||
|
||||
#if (IOV_MAX > 64)
|
||||
|
||||
@@ -24,6 +24,7 @@ ngx_os_io_t ngx_os_io = {
|
||||
ngx_readv_chain,
|
||||
ngx_udp_unix_recv,
|
||||
ngx_unix_send,
|
||||
ngx_udp_unix_send,
|
||||
ngx_writev_chain,
|
||||
0
|
||||
};
|
||||
|
||||
@@ -19,6 +19,7 @@ static ngx_os_io_t ngx_solaris_io = {
|
||||
ngx_readv_chain,
|
||||
ngx_udp_unix_recv,
|
||||
ngx_unix_send,
|
||||
ngx_udp_unix_send,
|
||||
#if (NGX_HAVE_SENDFILE)
|
||||
ngx_solaris_sendfilev_chain,
|
||||
NGX_IO_SENDFILE
|
||||
|
||||
56
src/os/unix/ngx_udp_send.c
Normal file
56
src/os/unix/ngx_udp_send.c
Normal file
@@ -0,0 +1,56 @@
|
||||
|
||||
/*
|
||||
* Copyright (C) Igor Sysoev
|
||||
* Copyright (C) Nginx, Inc.
|
||||
*/
|
||||
|
||||
|
||||
#include <ngx_config.h>
|
||||
#include <ngx_core.h>
|
||||
#include <ngx_event.h>
|
||||
|
||||
|
||||
ssize_t
|
||||
ngx_udp_unix_send(ngx_connection_t *c, u_char *buf, size_t size)
|
||||
{
|
||||
ssize_t n;
|
||||
ngx_err_t err;
|
||||
ngx_event_t *wev;
|
||||
|
||||
wev = c->write;
|
||||
|
||||
for ( ;; ) {
|
||||
n = sendto(c->fd, buf, size, 0, c->sockaddr, c->socklen);
|
||||
|
||||
ngx_log_debug4(NGX_LOG_DEBUG_EVENT, c->log, 0,
|
||||
"sendto: fd:%d %z of %uz to \"%V\"",
|
||||
c->fd, n, size, &c->addr_text);
|
||||
|
||||
if (n >= 0) {
|
||||
if ((size_t) n != size) {
|
||||
wev->error = 1;
|
||||
(void) ngx_connection_error(c, 0, "sendto() incomplete");
|
||||
return NGX_ERROR;
|
||||
}
|
||||
|
||||
c->sent += n;
|
||||
|
||||
return n;
|
||||
}
|
||||
|
||||
err = ngx_socket_errno;
|
||||
|
||||
if (err == NGX_EAGAIN) {
|
||||
wev->ready = 0;
|
||||
ngx_log_debug0(NGX_LOG_DEBUG_EVENT, c->log, NGX_EAGAIN,
|
||||
"sendto() not ready");
|
||||
return NGX_AGAIN;
|
||||
}
|
||||
|
||||
if (err != NGX_EINTR) {
|
||||
wev->error = 1;
|
||||
(void) ngx_connection_error(c, err, "sendto() failed");
|
||||
return NGX_ERROR;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user