FairRoot
Main Page
Related Pages
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Pages
rclose.c
Go to the documentation of this file.
1
/********************************************************************************
2
* Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
3
* *
4
* This software is distributed under the terms of the *
5
* GNU Lesser General Public Licence (LGPL) version 3, *
6
* copied verbatim in the file "LICENSE" *
7
********************************************************************************/
8
/********************************************************************
9
* Copyright:
10
* GSI, Gesellschaft fuer Schwerionenforschung mbH
11
* Planckstr. 1
12
* D-64291 Darmstadt
13
* Germany
14
********************************************************************
15
* rclose.c
16
* shutdown and close of socket
17
* created 23. 4.1999 by Horst Goeringer
18
********************************************************************
19
*/
20
// IWYU pragma: no_include <secure/_stdio.h>
21
#include <stdio.h>
// for printf, perror
22
#include <sys/socket.h>
// for shutdown
23
#include <unistd.h>
// for close
24
25
int
rclose
(
int
*piSocket,
int
iMode)
26
{
27
int
iSocket;
28
int
iRC;
29
// int iDebug = 0;
30
int
iError = 0;
31
int
iClose = 1;
32
char
cModule[32] =
"rclose"
;
33
char
cMsg[128] =
""
;
34
35
if
(iMode < 0) {
36
iMode = -iMode;
37
iClose = 0;
/* no shutdown, only close */
38
}
39
if
((iMode < 0) || (iMode > 3)) {
40
if
(iClose == 0)
41
iMode = -iMode;
42
printf(
"-E- %s: invalid shutdown mode: %d\n"
, cModule, iMode);
43
iError = 2;
44
}
45
46
iSocket = *piSocket;
47
if
(iSocket > 0) {
48
if
(iMode < 3) {
49
iRC = shutdown(iSocket, iMode);
50
if
(iRC) {
51
sprintf(cMsg,
"-E- %s: shutdown(%d) rc = %d"
, cModule, iMode, iRC);
52
perror(cMsg);
53
iError = -1;
54
}
55
/*
56
else if (iDebug)
57
printf(" %s: shutdown(%d) successfull\n",
58
cModule, iMode);
59
*/
60
}
61
62
if
(iClose) {
63
iRC = close(iSocket);
64
if
(iRC) {
65
sprintf(cMsg,
"-E- %s: close rc = %d"
, cModule, iRC);
66
perror(cMsg);
67
iError = -2;
68
}
69
/*
70
else if (iDebug)
71
printf(" %s: connection closed\n", cModule);
72
73
*/
74
}
/* (iClose) */
75
76
}
/* (iSocket > 0) */
77
else
{
78
printf(
"-E- %s: invalid socket: %d\n"
, cModule, iSocket);
79
iError = 1;
80
}
81
82
*piSocket = 0;
83
return
(iError);
84
85
}
/* rclose */
rclose
int rclose(int *, int)
Definition:
rclose.c:25
FairRoot
base
source
rclose.c
Generated on Mon Mar 8 2021 12:14:05 for FairRoot by
1.8.5