1322 * this will be true more so for DLPI_RAW mode with notifications
1323 * enabled.
1324 */
1325 if ((databuf == NULL && datalenp != NULL) ||
1326 (databuf != NULL && datalenp == NULL))
1327 return (DLPI_EINVAL);
1328
1329 pfd.fd = fd;
1330 pfd.events = POLLIN | POLLPRI;
1331
1332 ctl.buf = (dlreplyp == NULL) ? bufc : (void *)dlreplyp->dlm_msg;
1333 ctl.len = 0;
1334 ctl.maxlen = (dlreplyp == NULL) ? sizeof (bufc) : dlreplyp->dlm_msgsz;
1335
1336 data.buf = (databuf == NULL) ? bufd : databuf;
1337 data.len = 0;
1338 data.maxlen = (databuf == NULL) ? sizeof (bufd): *datalenp;
1339
1340 for (;;) {
1341 if (!infinite)
1342 start = gethrtime() / (NANOSEC / MILLISEC);
1343
1344 switch (poll(&pfd, 1, msec)) {
1345 default:
1346 if (pfd.revents & POLLHUP)
1347 return (DL_SYSERR);
1348 break;
1349 case 0:
1350 return (DLPI_ETIMEDOUT);
1351 case -1:
1352 return (DL_SYSERR);
1353 }
1354
1355 flags = 0;
1356 if ((retval = getmsg(fd, &ctl, &data, &flags)) < 0)
1357 return (DL_SYSERR);
1358
1359 if (totdatalenp != NULL)
1360 *totdatalenp = data.len;
1361
1362 /*
1438 */
1439 if (dlreplyp != NULL && ctl.len >= sizeof (t_uscalar_t)) {
1440 dlprim = dlreplyp->dlm_msg;
1441 if (dlprim->dl_primitive == dlreplyprim) {
1442 if (ctl.len < dlreplyminsz)
1443 return (DLPI_EBADMSG);
1444 dlreplyp->dlm_msgsz = ctl.len;
1445 break;
1446 } else if (dlprim->dl_primitive == DL_ERROR_ACK) {
1447 if (ctl.len < DL_ERROR_ACK_SIZE)
1448 return (DLPI_EBADMSG);
1449
1450 /* Is it ours? */
1451 if (dlprim->error_ack.dl_error_primitive ==
1452 dlreqprim)
1453 break;
1454 }
1455 }
1456 update_timer:
1457 if (!infinite) {
1458 current = gethrtime() / (NANOSEC / MILLISEC);
1459 msec -= (current - start);
1460
1461 if (msec <= 0)
1462 return (DLPI_ETIMEDOUT);
1463 }
1464 }
1465
1466 return (DLPI_SUCCESS);
1467 }
1468
1469 /*
1470 * Common routine invoked by all DLPI control routines. The inputs for this
1471 * function are:
1472 * dlpi_impl_t *dip: internal dlpi handle
1473 * const dlpi_msg_t *dlreqp: request message structure
1474 * dlpi_msg_t *dlreplyp: reply message structure
1475 * size_t dlreplyminsz: minimum size of reply primitive
1476 * int flags: flags to be set to send a message
1477 * This routine succeeds if the message is an expected request/acknowledged
1478 * message. However, if DLPI notification has been enabled via
|
1322 * this will be true more so for DLPI_RAW mode with notifications
1323 * enabled.
1324 */
1325 if ((databuf == NULL && datalenp != NULL) ||
1326 (databuf != NULL && datalenp == NULL))
1327 return (DLPI_EINVAL);
1328
1329 pfd.fd = fd;
1330 pfd.events = POLLIN | POLLPRI;
1331
1332 ctl.buf = (dlreplyp == NULL) ? bufc : (void *)dlreplyp->dlm_msg;
1333 ctl.len = 0;
1334 ctl.maxlen = (dlreplyp == NULL) ? sizeof (bufc) : dlreplyp->dlm_msgsz;
1335
1336 data.buf = (databuf == NULL) ? bufd : databuf;
1337 data.len = 0;
1338 data.maxlen = (databuf == NULL) ? sizeof (bufd): *datalenp;
1339
1340 for (;;) {
1341 if (!infinite)
1342 start = NSEC2MSEC(gethrtime());
1343
1344 switch (poll(&pfd, 1, msec)) {
1345 default:
1346 if (pfd.revents & POLLHUP)
1347 return (DL_SYSERR);
1348 break;
1349 case 0:
1350 return (DLPI_ETIMEDOUT);
1351 case -1:
1352 return (DL_SYSERR);
1353 }
1354
1355 flags = 0;
1356 if ((retval = getmsg(fd, &ctl, &data, &flags)) < 0)
1357 return (DL_SYSERR);
1358
1359 if (totdatalenp != NULL)
1360 *totdatalenp = data.len;
1361
1362 /*
1438 */
1439 if (dlreplyp != NULL && ctl.len >= sizeof (t_uscalar_t)) {
1440 dlprim = dlreplyp->dlm_msg;
1441 if (dlprim->dl_primitive == dlreplyprim) {
1442 if (ctl.len < dlreplyminsz)
1443 return (DLPI_EBADMSG);
1444 dlreplyp->dlm_msgsz = ctl.len;
1445 break;
1446 } else if (dlprim->dl_primitive == DL_ERROR_ACK) {
1447 if (ctl.len < DL_ERROR_ACK_SIZE)
1448 return (DLPI_EBADMSG);
1449
1450 /* Is it ours? */
1451 if (dlprim->error_ack.dl_error_primitive ==
1452 dlreqprim)
1453 break;
1454 }
1455 }
1456 update_timer:
1457 if (!infinite) {
1458 current = NSEC2MSEC(gethrtime());
1459 msec -= (current - start);
1460
1461 if (msec <= 0)
1462 return (DLPI_ETIMEDOUT);
1463 }
1464 }
1465
1466 return (DLPI_SUCCESS);
1467 }
1468
1469 /*
1470 * Common routine invoked by all DLPI control routines. The inputs for this
1471 * function are:
1472 * dlpi_impl_t *dip: internal dlpi handle
1473 * const dlpi_msg_t *dlreqp: request message structure
1474 * dlpi_msg_t *dlreplyp: reply message structure
1475 * size_t dlreplyminsz: minimum size of reply primitive
1476 * int flags: flags to be set to send a message
1477 * This routine succeeds if the message is an expected request/acknowledged
1478 * message. However, if DLPI notification has been enabled via
|