/*-
* Copyright (c) 2004,2009 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Wasabi Systems, Inc.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
rv = isns_socket_create(&(task_p->cfg_p->sd), ai_p->ai_family,
ai_p->ai_socktype);
if (rv != 0)
return;
rv = isns_socket_connect(task_p->cfg_p->sd, ai_p->ai_addr,
ai_p->ai_addrlen);
if (rv != 0) {
/* Add ISNS_EVT_TIMER_RECON to kqueue */
rv = isns_change_kevent_list(task_p->cfg_p,
(uintptr_t)ISNS_EVT_TIMER_RECON, EVFILT_TIMER, EV_ADD,
(int64_t)ISNS_EVT_TIMER_RECON_PERIOD_MS,
(intptr_t)isns_kevent_timer_recon);
if (rv == -1)
DBG("isns_task_reconnect_server: error on "
"isns_change_kevent_list(1)\n");
} else {
task_p->cfg_p->sd_connected = 1;
/* Add cfg_p->sd to kqueue */
rv = isns_change_kevent_list(task_p->cfg_p,
(uintptr_t)(task_p->cfg_p->sd), EVFILT_READ,
EV_ADD | EV_CLEAR, (int64_t)0,
(intptr_t)isns_kevent_socket);
if (rv == -1)
DBG("isns_task_reconnect_server: error on "
"isns_change_kevent_lists(2)\n");
isns_end_task(task_p);
}
}
/*
* isns_task_send_pdu()
*
* We send all of the pdu's associated with transaction task_p->trans_p here.
*
* Assumptions:
* (1) task_p->trans_p->pdu_req_list is an ordered (seq_id) list of
* related (trans_id), appropriately sized pdus to be sent. The first
* pdu has flag ISNS_FLAG_FIRST_PDU set and the last pdu has flag
* ISNS_FLAG_LAST_PDU set.
*/
static void
isns_task_send_pdu(struct isns_task_s *task_p)
{
struct iovec *iovp;
struct isns_config_s *cfg_p;
struct isns_pdu_s *pdu_p; /* points to first pdu in pdu_req_list */
struct isns_buffer_s *buf_p;
ssize_t bytes_written;
ssize_t count;
size_t bytes_to_write;
int iovcnt, cur_iovec;
char *ptr;
if (cfg_p->sd_connected) {
isns_socket_close(cfg_p->sd);
cfg_p->sd_connected = 0;
/* We may have received part of an unsolicited/duplicate pdu */
if (cfg_p->pdu_in_p != NULL) {
isns_free_pdu(cfg_p->pdu_in_p);
cfg_p->pdu_in_p = NULL;
}
}
/* May have an allocated 'struct addrinfo', whether connected or not */
if (cfg_p->ai_p != NULL) {
isns_free(cfg_p->ai_p);
cfg_p->ai_p = NULL;
}