Deleted Added
full compact
proto_common.c (223143) proto_common.c (229945)
1/*-
2 * Copyright (c) 2009-2010 The FreeBSD Foundation
3 * Copyright (c) 2011 Pawel Jakub Dawidek <pawel@dawidek.net>
4 * All rights reserved.
5 *
6 * This software was developed by Pawel Jakub Dawidek under sponsorship from
7 * the FreeBSD Foundation.
8 *

--- 15 unchanged lines hidden (view full) ---

24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 * SUCH DAMAGE.
29 */
30
31#include <sys/cdefs.h>
1/*-
2 * Copyright (c) 2009-2010 The FreeBSD Foundation
3 * Copyright (c) 2011 Pawel Jakub Dawidek <pawel@dawidek.net>
4 * All rights reserved.
5 *
6 * This software was developed by Pawel Jakub Dawidek under sponsorship from
7 * the FreeBSD Foundation.
8 *

--- 15 unchanged lines hidden (view full) ---

24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 * SUCH DAMAGE.
29 */
30
31#include <sys/cdefs.h>
32__FBSDID("$FreeBSD: head/sbin/hastd/proto_common.c 223143 2011-06-16 08:31:06Z sobomax $");
32__FBSDID("$FreeBSD: head/sbin/hastd/proto_common.c 229945 2012-01-10 22:39:07Z pjd $");
33
34#include <sys/types.h>
35#include <sys/socket.h>
36
37#include <errno.h>
38#include <fcntl.h>
39#include <stdbool.h>
40#include <stdlib.h>

--- 70 unchanged lines hidden (view full) ---

111 PJDLOG_ASSERT(data != NULL);
112 PJDLOG_ASSERT(size > 0);
113
114 do {
115 sendsize = size < MAX_SEND_SIZE ? size : MAX_SEND_SIZE;
116 done = send(sock, data, sendsize, MSG_NOSIGNAL);
117 if (done == 0) {
118 return (ENOTCONN);
33
34#include <sys/types.h>
35#include <sys/socket.h>
36
37#include <errno.h>
38#include <fcntl.h>
39#include <stdbool.h>
40#include <stdlib.h>

--- 70 unchanged lines hidden (view full) ---

111 PJDLOG_ASSERT(data != NULL);
112 PJDLOG_ASSERT(size > 0);
113
114 do {
115 sendsize = size < MAX_SEND_SIZE ? size : MAX_SEND_SIZE;
116 done = send(sock, data, sendsize, MSG_NOSIGNAL);
117 if (done == 0) {
118 return (ENOTCONN);
119 } else if (done < 0) {
119 } else if (done == -1) {
120 if (errno == EINTR)
121 continue;
122 if (errno == ENOBUFS) {
123 /*
124 * If there are no buffers we retry.
125 * After each try we increase delay before the
126 * next one and we give up after fifteen times.
127 * This gives 11s of total wait time.

--- 82 unchanged lines hidden (view full) ---

210 PJDLOG_ASSERT(data != NULL);
211 PJDLOG_ASSERT(size > 0);
212
213 do {
214 done = recv(sock, data, size, MSG_WAITALL);
215 } while (done == -1 && errno == EINTR);
216 if (done == 0) {
217 return (ENOTCONN);
120 if (errno == EINTR)
121 continue;
122 if (errno == ENOBUFS) {
123 /*
124 * If there are no buffers we retry.
125 * After each try we increase delay before the
126 * next one and we give up after fifteen times.
127 * This gives 11s of total wait time.

--- 82 unchanged lines hidden (view full) ---

210 PJDLOG_ASSERT(data != NULL);
211 PJDLOG_ASSERT(size > 0);
212
213 do {
214 done = recv(sock, data, size, MSG_WAITALL);
215 } while (done == -1 && errno == EINTR);
216 if (done == 0) {
217 return (ENOTCONN);
218 } else if (done < 0) {
218 } else if (done == -1) {
219 /*
220 * If this is blocking socket and we got EAGAIN, this
221 * means the request timed out. Translate errno to
222 * ETIMEDOUT, to give administrator a hint to
223 * eventually increase timeout.
224 */
225 if (errno == EAGAIN && blocking_socket(sock))
226 errno = ETIMEDOUT;
227 return (errno);
228 }
229 if (fdp == NULL)
230 return (0);
231 return (proto_descriptor_recv(sock, fdp));
232}
219 /*
220 * If this is blocking socket and we got EAGAIN, this
221 * means the request timed out. Translate errno to
222 * ETIMEDOUT, to give administrator a hint to
223 * eventually increase timeout.
224 */
225 if (errno == EAGAIN && blocking_socket(sock))
226 errno = ETIMEDOUT;
227 return (errno);
228 }
229 if (fdp == NULL)
230 return (0);
231 return (proto_descriptor_recv(sock, fdp));
232}