685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
|
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
|
-
-
+
+
-
-
-
-
-
-
+
-
-
-
-
+
-
-
-
-
+
+
+
-
-
+
+
-
+
-
|
static int
TcpClose2Proc(
void *instanceData, /* The socket to close. */
Tcl_Interp *interp, /* For error reporting. */
int flags) /* Flags that indicate which side to close. */
{
TcpState *statePtr = (TcpState *)instanceData;
int errorCode = 0;
int sd;
int readError = 0;
int writeError = 0;
/*
* Shutdown the OS socket handle.
*/
switch(flags) {
case TCL_CLOSE_READ:
sd = SHUT_RD;
break;
case TCL_CLOSE_WRITE:
if ((flags & (TCL_CLOSE_READ|TCL_CLOSE_WRITE)) == 0) {
sd = SHUT_WR;
break;
default:
if (interp) {
return TcpCloseProc(instanceData, interp);
Tcl_SetObjResult(interp, Tcl_NewStringObj(
"socket close2proc called bidirectionally", -1));
}
return TCL_ERROR;
}
if ((flags & TCL_CLOSE_READ) && (shutdown(statePtr->fds.fd, SHUT_RD) < 0)) {
readError = errno;
}
if (shutdown(statePtr->fds.fd,sd) < 0) {
errorCode = errno;
if ((flags & TCL_CLOSE_WRITE) && (shutdown(statePtr->fds.fd, SHUT_WR) < 0)) {
writeError = errno;
}
return (readError != 0) ? readError : writeError;
return errorCode;
}
/*
*----------------------------------------------------------------------
*
* TcpHostPortList --
*
|