Compare commits
No commits in common. "master" and "origin" have entirely different histories.
78 changed files with 2618 additions and 3009 deletions
6
.gitignore
vendored
6
.gitignore
vendored
|
@ -1,6 +0,0 @@
|
||||||
*.a
|
|
||||||
*.c~
|
|
||||||
*.h~
|
|
||||||
*.log
|
|
||||||
*.o
|
|
||||||
test/test_*
|
|
3
.ssh-agent
Normal file
3
.ssh-agent
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
SSH_AUTH_SOCK=/tmp/ssh-QHib2992/agent.2992; export SSH_AUTH_SOCK;
|
||||||
|
SSH_AGENT_PID=2993; export SSH_AGENT_PID;
|
||||||
|
echo Agent pid 2993;
|
20
HEADER
Normal file
20
HEADER
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
#-------------------------------------------------------------------%
|
||||||
|
#
|
||||||
|
# LIBNAZGUL : Library
|
||||||
|
#
|
||||||
|
#-------------------------------------------------------------------%
|
||||||
|
#
|
||||||
|
# IUP GMI 2, Module de Système. 2003-2004.
|
||||||
|
# Cours de J-M. Rifflet.
|
||||||
|
#
|
||||||
|
#-------------------------------------------------------------------%
|
||||||
|
#
|
||||||
|
# Projet de :
|
||||||
|
# Glenn ROLLAND,
|
||||||
|
# Sebastian SCHAWOHL,
|
||||||
|
# Rivka ZANA
|
||||||
|
#
|
||||||
|
# pour plus de détails au sujet du projet, voir le
|
||||||
|
# fichier README
|
||||||
|
#
|
||||||
|
#-------------------------------------------------------------------%
|
607
LICENSE
607
LICENSE
|
@ -1,25 +1,23 @@
|
||||||
GNU LIBRARY GENERAL PUBLIC LICENSE
|
|
||||||
Version 2, June 1991
|
|
||||||
|
|
||||||
Copyright (C) 1991 Free Software Foundation, Inc.
|
GNU GENERAL PUBLIC LICENSE
|
||||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
Version 2, June 1991
|
||||||
|
|
||||||
|
Copyright (C) 1989, 1991 Free Software Foundation, Inc.
|
||||||
|
675 Mass Ave, Cambridge, MA 02139, USA
|
||||||
Everyone is permitted to copy and distribute verbatim copies
|
Everyone is permitted to copy and distribute verbatim copies
|
||||||
of this license document, but changing it is not allowed.
|
of this license document, but changing it is not allowed.
|
||||||
|
|
||||||
[This is the first released version of the library GPL. It is
|
Preamble
|
||||||
numbered 2 because it goes with version 2 of the ordinary GPL.]
|
|
||||||
|
|
||||||
Preamble
|
|
||||||
|
|
||||||
The licenses for most software are designed to take away your
|
The licenses for most software are designed to take away your
|
||||||
freedom to share and change it. By contrast, the GNU General Public
|
freedom to share and change it. By contrast, the GNU General Public
|
||||||
Licenses are intended to guarantee your freedom to share and change
|
License is intended to guarantee your freedom to share and change free
|
||||||
free software--to make sure the software is free for all its users.
|
software--to make sure the software is free for all its users. This
|
||||||
|
General Public License applies to most of the Free Software
|
||||||
This license, the Library General Public License, applies to some
|
Foundation's software and to any other program whose authors commit to
|
||||||
specially designated Free Software Foundation software, and to any
|
using it. (Some other Free Software Foundation software is covered by
|
||||||
other libraries whose authors decide to use it. You can use it for
|
the GNU Library General Public License instead.) You can apply it to
|
||||||
your libraries, too.
|
your programs, too.
|
||||||
|
|
||||||
When we speak of free software, we are referring to freedom, not
|
When we speak of free software, we are referring to freedom, not
|
||||||
price. Our General Public Licenses are designed to make sure that you
|
price. Our General Public Licenses are designed to make sure that you
|
||||||
|
@ -30,347 +28,195 @@ in new free programs; and that you know you can do these things.
|
||||||
|
|
||||||
To protect your rights, we need to make restrictions that forbid
|
To protect your rights, we need to make restrictions that forbid
|
||||||
anyone to deny you these rights or to ask you to surrender the rights.
|
anyone to deny you these rights or to ask you to surrender the rights.
|
||||||
These restrictions translate to certain responsibilities for you if
|
These restrictions translate to certain responsibilities for you if you
|
||||||
you distribute copies of the library, or if you modify it.
|
distribute copies of the software, or if you modify it.
|
||||||
|
|
||||||
For example, if you distribute copies of the library, whether gratis
|
For example, if you distribute copies of such a program, whether
|
||||||
or for a fee, you must give the recipients all the rights that we gave
|
gratis or for a fee, you must give the recipients all the rights that
|
||||||
you. You must make sure that they, too, receive or can get the source
|
you have. You must make sure that they, too, receive or can get the
|
||||||
code. If you link a program with the library, you must provide
|
source code. And you must show them these terms so they know their
|
||||||
complete object files to the recipients so that they can relink them
|
rights.
|
||||||
with the library, after making changes to the library and recompiling
|
|
||||||
it. And you must show them these terms so they know their rights.
|
|
||||||
|
|
||||||
Our method of protecting your rights has two steps: (1) copyright
|
We protect your rights with two steps: (1) copyright the software, and
|
||||||
the library, and (2) offer you this license which gives you legal
|
(2) offer you this license which gives you legal permission to copy,
|
||||||
permission to copy, distribute and/or modify the library.
|
distribute and/or modify the software.
|
||||||
|
|
||||||
Also, for each distributor's protection, we want to make certain
|
Also, for each author's protection and ours, we want to make certain
|
||||||
that everyone understands that there is no warranty for this free
|
that everyone understands that there is no warranty for this free
|
||||||
library. If the library is modified by someone else and passed on, we
|
software. If the software is modified by someone else and passed on, we
|
||||||
want its recipients to know that what they have is not the original
|
want its recipients to know that what they have is not the original, so
|
||||||
version, so that any problems introduced by others will not reflect on
|
that any problems introduced by others will not reflect on the original
|
||||||
the original authors' reputations.
|
authors' reputations.
|
||||||
|
|
||||||
Finally, any free program is threatened constantly by software
|
Finally, any free program is threatened constantly by software
|
||||||
patents. We wish to avoid the danger that companies distributing free
|
patents. We wish to avoid the danger that redistributors of a free
|
||||||
software will individually obtain patent licenses, thus in effect
|
program will individually obtain patent licenses, in effect making the
|
||||||
transforming the program into proprietary software. To prevent this,
|
program proprietary. To prevent this, we have made it clear that any
|
||||||
we have made it clear that any patent must be licensed for everyone's
|
patent must be licensed for everyone's free use or not licensed at all.
|
||||||
free use or not licensed at all.
|
|
||||||
|
|
||||||
Most GNU software, including some libraries, is covered by the ordinary
|
|
||||||
GNU General Public License, which was designed for utility programs. This
|
|
||||||
license, the GNU Library General Public License, applies to certain
|
|
||||||
designated libraries. This license is quite different from the ordinary
|
|
||||||
one; be sure to read it in full, and don't assume that anything in it is
|
|
||||||
the same as in the ordinary license.
|
|
||||||
|
|
||||||
The reason we have a separate public license for some libraries is that
|
|
||||||
they blur the distinction we usually make between modifying or adding to a
|
|
||||||
program and simply using it. Linking a program with a library, without
|
|
||||||
changing the library, is in some sense simply using the library, and is
|
|
||||||
analogous to running a utility program or application program. However, in
|
|
||||||
a textual and legal sense, the linked executable is a combined work, a
|
|
||||||
derivative of the original library, and the ordinary General Public License
|
|
||||||
treats it as such.
|
|
||||||
|
|
||||||
Because of this blurred distinction, using the ordinary General
|
|
||||||
Public License for libraries did not effectively promote software
|
|
||||||
sharing, because most developers did not use the libraries. We
|
|
||||||
concluded that weaker conditions might promote sharing better.
|
|
||||||
|
|
||||||
However, unrestricted linking of non-free programs would deprive the
|
|
||||||
users of those programs of all benefit from the free status of the
|
|
||||||
libraries themselves. This Library General Public License is intended to
|
|
||||||
permit developers of non-free programs to use free libraries, while
|
|
||||||
preserving your freedom as a user of such programs to change the free
|
|
||||||
libraries that are incorporated in them. (We have not seen how to achieve
|
|
||||||
this as regards changes in header files, but we have achieved it as regards
|
|
||||||
changes in the actual functions of the Library.) The hope is that this
|
|
||||||
will lead to faster development of free libraries.
|
|
||||||
|
|
||||||
The precise terms and conditions for copying, distribution and
|
The precise terms and conditions for copying, distribution and
|
||||||
modification follow. Pay close attention to the difference between a
|
modification follow.
|
||||||
"work based on the library" and a "work that uses the library". The
|
|
||||||
former contains code derived from the library, while the latter only
|
|
||||||
works together with the library.
|
|
||||||
|
|
||||||
Note that it is possible for a library to be covered by the ordinary
|
|
||||||
General Public License rather than by this special one.
|
|
||||||
|
|
||||||
GNU LIBRARY GENERAL PUBLIC LICENSE
|
GNU GENERAL PUBLIC LICENSE
|
||||||
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
||||||
|
|
||||||
0. This License Agreement applies to any software library which
|
0. This License applies to any program or other work which contains
|
||||||
contains a notice placed by the copyright holder or other authorized
|
a notice placed by the copyright holder saying it may be distributed
|
||||||
party saying it may be distributed under the terms of this Library
|
under the terms of this General Public License. The "Program", below,
|
||||||
General Public License (also called "this License"). Each licensee is
|
refers to any such program or work, and a "work based on the Program"
|
||||||
addressed as "you".
|
means either the Program or any derivative work under copyright law:
|
||||||
|
that is to say, a work containing the Program or a portion of it,
|
||||||
|
either verbatim or with modifications and/or translated into another
|
||||||
|
language. (Hereinafter, translation is included without limitation in
|
||||||
|
the term "modification".) Each licensee is addressed as "you".
|
||||||
|
|
||||||
A "library" means a collection of software functions and/or data
|
Activities other than copying, distribution and modification are not
|
||||||
prepared so as to be conveniently linked with application programs
|
|
||||||
(which use some of those functions and data) to form executables.
|
|
||||||
|
|
||||||
The "Library", below, refers to any such software library or work
|
|
||||||
which has been distributed under these terms. A "work based on the
|
|
||||||
Library" means either the Library or any derivative work under
|
|
||||||
copyright law: that is to say, a work containing the Library or a
|
|
||||||
portion of it, either verbatim or with modifications and/or translated
|
|
||||||
straightforwardly into another language. (Hereinafter, translation is
|
|
||||||
included without limitation in the term "modification".)
|
|
||||||
|
|
||||||
"Source code" for a work means the preferred form of the work for
|
|
||||||
making modifications to it. For a library, complete source code means
|
|
||||||
all the source code for all modules it contains, plus any associated
|
|
||||||
interface definition files, plus the scripts used to control compilation
|
|
||||||
and installation of the library.
|
|
||||||
|
|
||||||
Activities other than copying, distribution and modification are not
|
|
||||||
covered by this License; they are outside its scope. The act of
|
covered by this License; they are outside its scope. The act of
|
||||||
running a program using the Library is not restricted, and output from
|
running the Program is not restricted, and the output from the Program
|
||||||
such a program is covered only if its contents constitute a work based
|
is covered only if its contents constitute a work based on the
|
||||||
on the Library (independent of the use of the Library in a tool for
|
Program (independent of having been made by running the Program).
|
||||||
writing it). Whether that is true depends on what the Library does
|
Whether that is true depends on what the Program does.
|
||||||
and what the program that uses the Library does.
|
|
||||||
|
|
||||||
1. You may copy and distribute verbatim copies of the Library's
|
|
||||||
complete source code as you receive it, in any medium, provided that
|
|
||||||
you conspicuously and appropriately publish on each copy an
|
|
||||||
appropriate copyright notice and disclaimer of warranty; keep intact
|
|
||||||
all the notices that refer to this License and to the absence of any
|
|
||||||
warranty; and distribute a copy of this License along with the
|
|
||||||
Library.
|
|
||||||
|
|
||||||
You may charge a fee for the physical act of transferring a copy,
|
1. You may copy and distribute verbatim copies of the Program's
|
||||||
and you may at your option offer warranty protection in exchange for a
|
source code as you receive it, in any medium, provided that you
|
||||||
fee.
|
conspicuously and appropriately publish on each copy an appropriate
|
||||||
|
copyright notice and disclaimer of warranty; keep intact all the
|
||||||
2. You may modify your copy or copies of the Library or any portion
|
notices that refer to this License and to the absence of any warranty;
|
||||||
of it, thus forming a work based on the Library, and copy and
|
and give any other recipients of the Program a copy of this License
|
||||||
|
along with the Program.
|
||||||
|
|
||||||
|
You may charge a fee for the physical act of transferring a copy, and
|
||||||
|
you may at your option offer warranty protection in exchange for a fee.
|
||||||
|
|
||||||
|
2. You may modify your copy or copies of the Program or any portion
|
||||||
|
of it, thus forming a work based on the Program, and copy and
|
||||||
distribute such modifications or work under the terms of Section 1
|
distribute such modifications or work under the terms of Section 1
|
||||||
above, provided that you also meet all of these conditions:
|
above, provided that you also meet all of these conditions:
|
||||||
|
|
||||||
a) The modified work must itself be a software library.
|
a) You must cause the modified files to carry prominent notices
|
||||||
|
|
||||||
b) You must cause the files modified to carry prominent notices
|
|
||||||
stating that you changed the files and the date of any change.
|
stating that you changed the files and the date of any change.
|
||||||
|
|
||||||
c) You must cause the whole of the work to be licensed at no
|
b) You must cause any work that you distribute or publish, that in
|
||||||
charge to all third parties under the terms of this License.
|
whole or in part contains or is derived from the Program or any
|
||||||
|
part thereof, to be licensed as a whole at no charge to all third
|
||||||
d) If a facility in the modified Library refers to a function or a
|
parties under the terms of this License.
|
||||||
table of data to be supplied by an application program that uses
|
|
||||||
the facility, other than as an argument passed when the facility
|
|
||||||
is invoked, then you must make a good faith effort to ensure that,
|
|
||||||
in the event an application does not supply such function or
|
|
||||||
table, the facility still operates, and performs whatever part of
|
|
||||||
its purpose remains meaningful.
|
|
||||||
|
|
||||||
(For example, a function in a library to compute square roots has
|
|
||||||
a purpose that is entirely well-defined independent of the
|
|
||||||
application. Therefore, Subsection 2d requires that any
|
|
||||||
application-supplied function or table used by this function must
|
|
||||||
be optional: if the application does not supply it, the square
|
|
||||||
root function must still compute square roots.)
|
|
||||||
|
|
||||||
|
c) If the modified program normally reads commands interactively
|
||||||
|
when run, you must cause it, when started running for such
|
||||||
|
interactive use in the most ordinary way, to print or display an
|
||||||
|
announcement including an appropriate copyright notice and a
|
||||||
|
notice that there is no warranty (or else, saying that you provide
|
||||||
|
a warranty) and that users may redistribute the program under
|
||||||
|
these conditions, and telling the user how to view a copy of this
|
||||||
|
License. (Exception: if the Program itself is interactive but
|
||||||
|
does not normally print such an announcement, your work based on
|
||||||
|
the Program is not required to print an announcement.)
|
||||||
|
|
||||||
These requirements apply to the modified work as a whole. If
|
These requirements apply to the modified work as a whole. If
|
||||||
identifiable sections of that work are not derived from the Library,
|
identifiable sections of that work are not derived from the Program,
|
||||||
and can be reasonably considered independent and separate works in
|
and can be reasonably considered independent and separate works in
|
||||||
themselves, then this License, and its terms, do not apply to those
|
themselves, then this License, and its terms, do not apply to those
|
||||||
sections when you distribute them as separate works. But when you
|
sections when you distribute them as separate works. But when you
|
||||||
distribute the same sections as part of a whole which is a work based
|
distribute the same sections as part of a whole which is a work based
|
||||||
on the Library, the distribution of the whole must be on the terms of
|
on the Program, the distribution of the whole must be on the terms of
|
||||||
this License, whose permissions for other licensees extend to the
|
this License, whose permissions for other licensees extend to the
|
||||||
entire whole, and thus to each and every part regardless of who wrote
|
entire whole, and thus to each and every part regardless of who wrote it.
|
||||||
it.
|
|
||||||
|
|
||||||
Thus, it is not the intent of this section to claim rights or contest
|
Thus, it is not the intent of this section to claim rights or contest
|
||||||
your rights to work written entirely by you; rather, the intent is to
|
your rights to work written entirely by you; rather, the intent is to
|
||||||
exercise the right to control the distribution of derivative or
|
exercise the right to control the distribution of derivative or
|
||||||
collective works based on the Library.
|
collective works based on the Program.
|
||||||
|
|
||||||
In addition, mere aggregation of another work not based on the Library
|
In addition, mere aggregation of another work not based on the Program
|
||||||
with the Library (or with a work based on the Library) on a volume of
|
with the Program (or with a work based on the Program) on a volume of
|
||||||
a storage or distribution medium does not bring the other work under
|
a storage or distribution medium does not bring the other work under
|
||||||
the scope of this License.
|
the scope of this License.
|
||||||
|
|
||||||
3. You may opt to apply the terms of the ordinary GNU General Public
|
3. You may copy and distribute the Program (or a work based on it,
|
||||||
License instead of this License to a given copy of the Library. To do
|
under Section 2) in object code or executable form under the terms of
|
||||||
this, you must alter all the notices that refer to this License, so
|
Sections 1 and 2 above provided that you also do one of the following:
|
||||||
that they refer to the ordinary GNU General Public License, version 2,
|
|
||||||
instead of to this License. (If a newer version than version 2 of the
|
|
||||||
ordinary GNU General Public License has appeared, then you can specify
|
|
||||||
that version instead if you wish.) Do not make any other change in
|
|
||||||
these notices.
|
|
||||||
|
|
||||||
Once this change is made in a given copy, it is irreversible for
|
|
||||||
that copy, so the ordinary GNU General Public License applies to all
|
|
||||||
subsequent copies and derivative works made from that copy.
|
|
||||||
|
|
||||||
This option is useful when you wish to copy part of the code of
|
a) Accompany it with the complete corresponding machine-readable
|
||||||
the Library into a program that is not a library.
|
source code, which must be distributed under the terms of Sections
|
||||||
|
1 and 2 above on a medium customarily used for software interchange; or,
|
||||||
|
|
||||||
4. You may copy and distribute the Library (or a portion or
|
b) Accompany it with a written offer, valid for at least three
|
||||||
derivative of it, under Section 2) in object code or executable form
|
years, to give any third party, for a charge no more than your
|
||||||
under the terms of Sections 1 and 2 above provided that you accompany
|
cost of physically performing source distribution, a complete
|
||||||
it with the complete corresponding machine-readable source code, which
|
machine-readable copy of the corresponding source code, to be
|
||||||
must be distributed under the terms of Sections 1 and 2 above on a
|
distributed under the terms of Sections 1 and 2 above on a medium
|
||||||
medium customarily used for software interchange.
|
customarily used for software interchange; or,
|
||||||
|
|
||||||
If distribution of object code is made by offering access to copy
|
c) Accompany it with the information you received as to the offer
|
||||||
from a designated place, then offering equivalent access to copy the
|
to distribute corresponding source code. (This alternative is
|
||||||
source code from the same place satisfies the requirement to
|
allowed only for noncommercial distribution and only if you
|
||||||
distribute the source code, even though third parties are not
|
received the program in object code or executable form with such
|
||||||
|
an offer, in accord with Subsection b above.)
|
||||||
|
|
||||||
|
The source code for a work means the preferred form of the work for
|
||||||
|
making modifications to it. For an executable work, complete source
|
||||||
|
code means all the source code for all modules it contains, plus any
|
||||||
|
associated interface definition files, plus the scripts used to
|
||||||
|
control compilation and installation of the executable. However, as a
|
||||||
|
special exception, the source code distributed need not include
|
||||||
|
anything that is normally distributed (in either source or binary
|
||||||
|
form) with the major components (compiler, kernel, and so on) of the
|
||||||
|
operating system on which the executable runs, unless that component
|
||||||
|
itself accompanies the executable.
|
||||||
|
|
||||||
|
If distribution of executable or object code is made by offering
|
||||||
|
access to copy from a designated place, then offering equivalent
|
||||||
|
access to copy the source code from the same place counts as
|
||||||
|
distribution of the source code, even though third parties are not
|
||||||
compelled to copy the source along with the object code.
|
compelled to copy the source along with the object code.
|
||||||
|
|
||||||
5. A program that contains no derivative of any portion of the
|
|
||||||
Library, but is designed to work with the Library by being compiled or
|
|
||||||
linked with it, is called a "work that uses the Library". Such a
|
|
||||||
work, in isolation, is not a derivative work of the Library, and
|
|
||||||
therefore falls outside the scope of this License.
|
|
||||||
|
|
||||||
However, linking a "work that uses the Library" with the Library
|
|
||||||
creates an executable that is a derivative of the Library (because it
|
|
||||||
contains portions of the Library), rather than a "work that uses the
|
|
||||||
library". The executable is therefore covered by this License.
|
|
||||||
Section 6 states terms for distribution of such executables.
|
|
||||||
|
|
||||||
When a "work that uses the Library" uses material from a header file
|
|
||||||
that is part of the Library, the object code for the work may be a
|
|
||||||
derivative work of the Library even though the source code is not.
|
|
||||||
Whether this is true is especially significant if the work can be
|
|
||||||
linked without the Library, or if the work is itself a library. The
|
|
||||||
threshold for this to be true is not precisely defined by law.
|
|
||||||
|
|
||||||
If such an object file uses only numerical parameters, data
|
|
||||||
structure layouts and accessors, and small macros and small inline
|
|
||||||
functions (ten lines or less in length), then the use of the object
|
|
||||||
file is unrestricted, regardless of whether it is legally a derivative
|
|
||||||
work. (Executables containing this object code plus portions of the
|
|
||||||
Library will still fall under Section 6.)
|
|
||||||
|
|
||||||
Otherwise, if the work is a derivative of the Library, you may
|
|
||||||
distribute the object code for the work under the terms of Section 6.
|
|
||||||
Any executables containing that work also fall under Section 6,
|
|
||||||
whether or not they are linked directly with the Library itself.
|
|
||||||
|
|
||||||
6. As an exception to the Sections above, you may also compile or
|
4. You may not copy, modify, sublicense, or distribute the Program
|
||||||
link a "work that uses the Library" with the Library to produce a
|
except as expressly provided under this License. Any attempt
|
||||||
work containing portions of the Library, and distribute that work
|
otherwise to copy, modify, sublicense or distribute the Program is
|
||||||
under terms of your choice, provided that the terms permit
|
void, and will automatically terminate your rights under this License.
|
||||||
modification of the work for the customer's own use and reverse
|
However, parties who have received copies, or rights, from you under
|
||||||
engineering for debugging such modifications.
|
this License will not have their licenses terminated so long as such
|
||||||
|
parties remain in full compliance.
|
||||||
|
|
||||||
You must give prominent notice with each copy of the work that the
|
5. You are not required to accept this License, since you have not
|
||||||
Library is used in it and that the Library and its use are covered by
|
|
||||||
this License. You must supply a copy of this License. If the work
|
|
||||||
during execution displays copyright notices, you must include the
|
|
||||||
copyright notice for the Library among them, as well as a reference
|
|
||||||
directing the user to the copy of this License. Also, you must do one
|
|
||||||
of these things:
|
|
||||||
|
|
||||||
a) Accompany the work with the complete corresponding
|
|
||||||
machine-readable source code for the Library including whatever
|
|
||||||
changes were used in the work (which must be distributed under
|
|
||||||
Sections 1 and 2 above); and, if the work is an executable linked
|
|
||||||
with the Library, with the complete machine-readable "work that
|
|
||||||
uses the Library", as object code and/or source code, so that the
|
|
||||||
user can modify the Library and then relink to produce a modified
|
|
||||||
executable containing the modified Library. (It is understood
|
|
||||||
that the user who changes the contents of definitions files in the
|
|
||||||
Library will not necessarily be able to recompile the application
|
|
||||||
to use the modified definitions.)
|
|
||||||
|
|
||||||
b) Accompany the work with a written offer, valid for at
|
|
||||||
least three years, to give the same user the materials
|
|
||||||
specified in Subsection 6a, above, for a charge no more
|
|
||||||
than the cost of performing this distribution.
|
|
||||||
|
|
||||||
c) If distribution of the work is made by offering access to copy
|
|
||||||
from a designated place, offer equivalent access to copy the above
|
|
||||||
specified materials from the same place.
|
|
||||||
|
|
||||||
d) Verify that the user has already received a copy of these
|
|
||||||
materials or that you have already sent this user a copy.
|
|
||||||
|
|
||||||
For an executable, the required form of the "work that uses the
|
|
||||||
Library" must include any data and utility programs needed for
|
|
||||||
reproducing the executable from it. However, as a special exception,
|
|
||||||
the source code distributed need not include anything that is normally
|
|
||||||
distributed (in either source or binary form) with the major
|
|
||||||
components (compiler, kernel, and so on) of the operating system on
|
|
||||||
which the executable runs, unless that component itself accompanies
|
|
||||||
the executable.
|
|
||||||
|
|
||||||
It may happen that this requirement contradicts the license
|
|
||||||
restrictions of other proprietary libraries that do not normally
|
|
||||||
accompany the operating system. Such a contradiction means you cannot
|
|
||||||
use both them and the Library together in an executable that you
|
|
||||||
distribute.
|
|
||||||
|
|
||||||
7. You may place library facilities that are a work based on the
|
|
||||||
Library side-by-side in a single library together with other library
|
|
||||||
facilities not covered by this License, and distribute such a combined
|
|
||||||
library, provided that the separate distribution of the work based on
|
|
||||||
the Library and of the other library facilities is otherwise
|
|
||||||
permitted, and provided that you do these two things:
|
|
||||||
|
|
||||||
a) Accompany the combined library with a copy of the same work
|
|
||||||
based on the Library, uncombined with any other library
|
|
||||||
facilities. This must be distributed under the terms of the
|
|
||||||
Sections above.
|
|
||||||
|
|
||||||
b) Give prominent notice with the combined library of the fact
|
|
||||||
that part of it is a work based on the Library, and explaining
|
|
||||||
where to find the accompanying uncombined form of the same work.
|
|
||||||
|
|
||||||
8. You may not copy, modify, sublicense, link with, or distribute
|
|
||||||
the Library except as expressly provided under this License. Any
|
|
||||||
attempt otherwise to copy, modify, sublicense, link with, or
|
|
||||||
distribute the Library is void, and will automatically terminate your
|
|
||||||
rights under this License. However, parties who have received copies,
|
|
||||||
or rights, from you under this License will not have their licenses
|
|
||||||
terminated so long as such parties remain in full compliance.
|
|
||||||
|
|
||||||
9. You are not required to accept this License, since you have not
|
|
||||||
signed it. However, nothing else grants you permission to modify or
|
signed it. However, nothing else grants you permission to modify or
|
||||||
distribute the Library or its derivative works. These actions are
|
distribute the Program or its derivative works. These actions are
|
||||||
prohibited by law if you do not accept this License. Therefore, by
|
prohibited by law if you do not accept this License. Therefore, by
|
||||||
modifying or distributing the Library (or any work based on the
|
modifying or distributing the Program (or any work based on the
|
||||||
Library), you indicate your acceptance of this License to do so, and
|
Program), you indicate your acceptance of this License to do so, and
|
||||||
all its terms and conditions for copying, distributing or modifying
|
all its terms and conditions for copying, distributing or modifying
|
||||||
the Library or works based on it.
|
the Program or works based on it.
|
||||||
|
|
||||||
10. Each time you redistribute the Library (or any work based on the
|
6. Each time you redistribute the Program (or any work based on the
|
||||||
Library), the recipient automatically receives a license from the
|
Program), the recipient automatically receives a license from the
|
||||||
original licensor to copy, distribute, link with or modify the Library
|
original licensor to copy, distribute or modify the Program subject to
|
||||||
subject to these terms and conditions. You may not impose any further
|
these terms and conditions. You may not impose any further
|
||||||
restrictions on the recipients' exercise of the rights granted herein.
|
restrictions on the recipients' exercise of the rights granted herein.
|
||||||
You are not responsible for enforcing compliance by third parties to
|
You are not responsible for enforcing compliance by third parties to
|
||||||
this License.
|
this License.
|
||||||
|
|
||||||
11. If, as a consequence of a court judgment or allegation of patent
|
7. If, as a consequence of a court judgment or allegation of patent
|
||||||
infringement or for any other reason (not limited to patent issues),
|
infringement or for any other reason (not limited to patent issues),
|
||||||
conditions are imposed on you (whether by court order, agreement or
|
conditions are imposed on you (whether by court order, agreement or
|
||||||
otherwise) that contradict the conditions of this License, they do not
|
otherwise) that contradict the conditions of this License, they do not
|
||||||
excuse you from the conditions of this License. If you cannot
|
excuse you from the conditions of this License. If you cannot
|
||||||
distribute so as to satisfy simultaneously your obligations under this
|
distribute so as to satisfy simultaneously your obligations under this
|
||||||
License and any other pertinent obligations, then as a consequence you
|
License and any other pertinent obligations, then as a consequence you
|
||||||
may not distribute the Library at all. For example, if a patent
|
may not distribute the Program at all. For example, if a patent
|
||||||
license would not permit royalty-free redistribution of the Library by
|
license would not permit royalty-free redistribution of the Program by
|
||||||
all those who receive copies directly or indirectly through you, then
|
all those who receive copies directly or indirectly through you, then
|
||||||
the only way you could satisfy both it and this License would be to
|
the only way you could satisfy both it and this License would be to
|
||||||
refrain entirely from distribution of the Library.
|
refrain entirely from distribution of the Program.
|
||||||
|
|
||||||
If any portion of this section is held invalid or unenforceable under any
|
If any portion of this section is held invalid or unenforceable under
|
||||||
particular circumstance, the balance of the section is intended to apply,
|
any particular circumstance, the balance of the section is intended to
|
||||||
and the section as a whole is intended to apply in other circumstances.
|
apply and the section as a whole is intended to apply in other
|
||||||
|
circumstances.
|
||||||
|
|
||||||
It is not the purpose of this section to induce you to infringe any
|
It is not the purpose of this section to induce you to infringe any
|
||||||
patents or other property right claims or to contest validity of any
|
patents or other property right claims or to contest validity of any
|
||||||
such claims; this section has the sole purpose of protecting the
|
such claims; this section has the sole purpose of protecting the
|
||||||
integrity of the free software distribution system which is
|
integrity of the free software distribution system, which is
|
||||||
implemented by public license practices. Many people have made
|
implemented by public license practices. Many people have made
|
||||||
generous contributions to the wide range of software distributed
|
generous contributions to the wide range of software distributed
|
||||||
through that system in reliance on consistent application of that
|
through that system in reliance on consistent application of that
|
||||||
|
@ -380,102 +226,117 @@ impose that choice.
|
||||||
|
|
||||||
This section is intended to make thoroughly clear what is believed to
|
This section is intended to make thoroughly clear what is believed to
|
||||||
be a consequence of the rest of this License.
|
be a consequence of the rest of this License.
|
||||||
|
|
||||||
12. If the distribution and/or use of the Library is restricted in
|
8. If the distribution and/or use of the Program is restricted in
|
||||||
certain countries either by patents or by copyrighted interfaces, the
|
certain countries either by patents or by copyrighted interfaces, the
|
||||||
original copyright holder who places the Library under this License may add
|
original copyright holder who places the Program under this License
|
||||||
an explicit geographical distribution limitation excluding those countries,
|
may add an explicit geographical distribution limitation excluding
|
||||||
so that distribution is permitted only in or among countries not thus
|
those countries, so that distribution is permitted only in or among
|
||||||
excluded. In such case, this License incorporates the limitation as if
|
countries not thus excluded. In such case, this License incorporates
|
||||||
written in the body of this License.
|
the limitation as if written in the body of this License.
|
||||||
|
|
||||||
13. The Free Software Foundation may publish revised and/or new
|
9. The Free Software Foundation may publish revised and/or new versions
|
||||||
versions of the Library General Public License from time to time.
|
of the General Public License from time to time. Such new versions will
|
||||||
Such new versions will be similar in spirit to the present version,
|
be similar in spirit to the present version, but may differ in detail to
|
||||||
but may differ in detail to address new problems or concerns.
|
address new problems or concerns.
|
||||||
|
|
||||||
Each version is given a distinguishing version number. If the Library
|
Each version is given a distinguishing version number. If the Program
|
||||||
specifies a version number of this License which applies to it and
|
specifies a version number of this License which applies to it and "any
|
||||||
"any later version", you have the option of following the terms and
|
later version", you have the option of following the terms and conditions
|
||||||
conditions either of that version or of any later version published by
|
either of that version or of any later version published by the Free
|
||||||
the Free Software Foundation. If the Library does not specify a
|
Software Foundation. If the Program does not specify a version number of
|
||||||
license version number, you may choose any version ever published by
|
this License, you may choose any version ever published by the Free Software
|
||||||
the Free Software Foundation.
|
Foundation.
|
||||||
|
|
||||||
14. If you wish to incorporate parts of the Library into other free
|
|
||||||
programs whose distribution conditions are incompatible with these,
|
|
||||||
write to the author to ask for permission. For software which is
|
|
||||||
copyrighted by the Free Software Foundation, write to the Free
|
|
||||||
Software Foundation; we sometimes make exceptions for this. Our
|
|
||||||
decision will be guided by the two goals of preserving the free status
|
|
||||||
of all derivatives of our free software and of promoting the sharing
|
|
||||||
and reuse of software generally.
|
|
||||||
|
|
||||||
NO WARRANTY
|
10. If you wish to incorporate parts of the Program into other free
|
||||||
|
programs whose distribution conditions are different, write to the author
|
||||||
|
to ask for permission. For software which is copyrighted by the Free
|
||||||
|
Software Foundation, write to the Free Software Foundation; we sometimes
|
||||||
|
make exceptions for this. Our decision will be guided by the two goals
|
||||||
|
of preserving the free status of all derivatives of our free software and
|
||||||
|
of promoting the sharing and reuse of software generally.
|
||||||
|
|
||||||
15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO
|
NO WARRANTY
|
||||||
WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW.
|
|
||||||
EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR
|
|
||||||
OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY
|
|
||||||
KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE
|
|
||||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
|
||||||
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE
|
|
||||||
LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME
|
|
||||||
THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
|
||||||
|
|
||||||
16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN
|
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
|
||||||
WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY
|
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
|
||||||
AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU
|
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
|
||||||
FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR
|
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
|
||||||
CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE
|
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||||
LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
|
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
|
||||||
RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
|
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
|
||||||
FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
|
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
|
||||||
SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
|
REPAIR OR CORRECTION.
|
||||||
DAMAGES.
|
|
||||||
|
|
||||||
END OF TERMS AND CONDITIONS
|
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||||
|
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
|
||||||
How to Apply These Terms to Your New Libraries
|
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
|
||||||
|
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
|
||||||
|
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
|
||||||
|
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
|
||||||
|
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
|
||||||
|
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
|
||||||
|
POSSIBILITY OF SUCH DAMAGES.
|
||||||
|
|
||||||
If you develop a new library, and you want it to be of the greatest
|
END OF TERMS AND CONDITIONS
|
||||||
possible use to the public, we recommend making it free software that
|
|
||||||
everyone can redistribute and change. You can do so by permitting
|
|
||||||
redistribution under these terms (or, alternatively, under the terms of the
|
|
||||||
ordinary General Public License).
|
|
||||||
|
|
||||||
To apply these terms, attach the following notices to the library. It is
|
|
||||||
safest to attach them to the start of each source file to most effectively
|
|
||||||
convey the exclusion of warranty; and each file should have at least the
|
|
||||||
"copyright" line and a pointer to where the full notice is found.
|
|
||||||
|
|
||||||
<one line to give the library's name and a brief idea of what it does.>
|
How to Apply These Terms to Your New Programs
|
||||||
Copyright (C) <year> <name of author>
|
|
||||||
|
|
||||||
This library is free software; you can redistribute it and/or
|
If you develop a new program, and you want it to be of the greatest
|
||||||
modify it under the terms of the GNU Library General Public
|
possible use to the public, the best way to achieve this is to make it
|
||||||
License as published by the Free Software Foundation; either
|
free software which everyone can redistribute and change under these terms.
|
||||||
version 2 of the License, or (at your option) any later version.
|
|
||||||
|
|
||||||
This library is distributed in the hope that it will be useful,
|
To do so, attach the following notices to the program. It is safest
|
||||||
|
to attach them to the start of each source file to most effectively
|
||||||
|
convey the exclusion of warranty; and each file should have at least
|
||||||
|
the "copyright" line and a pointer to where the full notice is found.
|
||||||
|
|
||||||
|
<one line to give the program's name and a brief idea of what it does.>
|
||||||
|
Copyright (C) 19yy <name of author>
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation; either version 2 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
Library General Public License for more details.
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program; if not, write to the Free Software
|
||||||
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
|
||||||
You should have received a copy of the GNU Library General Public
|
|
||||||
License along with this library; if not, write to the Free Software
|
|
||||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
||||||
|
|
||||||
Also add information on how to contact you by electronic and paper mail.
|
Also add information on how to contact you by electronic and paper mail.
|
||||||
|
|
||||||
|
If the program is interactive, make it output a short notice like this
|
||||||
|
when it starts in an interactive mode:
|
||||||
|
|
||||||
|
Gnomovision version 69, Copyright (C) 19yy name of author
|
||||||
|
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||||
|
This is free software, and you are welcome to redistribute it
|
||||||
|
under certain conditions; type `show c' for details.
|
||||||
|
|
||||||
|
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||||
|
parts of the General Public License. Of course, the commands you use may
|
||||||
|
be called something other than `show w' and `show c'; they could even be
|
||||||
|
mouse-clicks or menu items--whatever suits your program.
|
||||||
|
|
||||||
You should also get your employer (if you work as a programmer) or your
|
You should also get your employer (if you work as a programmer) or your
|
||||||
school, if any, to sign a "copyright disclaimer" for the library, if
|
school, if any, to sign a "copyright disclaimer" for the program, if
|
||||||
necessary. Here is a sample; alter the names:
|
necessary. Here is a sample; alter the names:
|
||||||
|
|
||||||
Yoyodyne, Inc., hereby disclaims all copyright interest in the
|
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
|
||||||
library `Frob' (a library for tweaking knobs) written by James Random Hacker.
|
`Gnomovision' (which makes passes at compilers) written by James Hacker.
|
||||||
|
|
||||||
<signature of Ty Coon>, 1 April 1990
|
<signature of Ty Coon>, 1 April 1989
|
||||||
Ty Coon, President of Vice
|
Ty Coon, President of Vice
|
||||||
|
|
||||||
That's all there is to it!
|
This General Public License does not permit incorporating your program into
|
||||||
|
proprietary programs. If your program is a subroutine library, you may
|
||||||
|
consider it more useful to permit linking proprietary applications with the
|
||||||
|
library. If this is what you want to do, use the GNU Library General
|
||||||
|
Public License instead of this License.
|
||||||
|
|
51
Makefile
51
Makefile
|
@ -1,10 +1,35 @@
|
||||||
|
#-------------------------------------------------------------------%
|
||||||
|
#
|
||||||
|
# LIBNAZGUL : Library
|
||||||
|
#
|
||||||
|
#-------------------------------------------------------------------%
|
||||||
|
#
|
||||||
|
# IUP GMI 2, Module de Système. 2003-2004.
|
||||||
|
# Cours de J-M. Rifflet.
|
||||||
|
#
|
||||||
|
#-------------------------------------------------------------------%
|
||||||
|
#
|
||||||
|
# Projet de :
|
||||||
|
# Glenn ROLLAND,
|
||||||
|
# Sebastian SCHAWOHL,
|
||||||
|
# Rivka ZANA
|
||||||
|
#
|
||||||
|
# pour plus de détails au sujet du projet, voir le
|
||||||
|
# fichier README
|
||||||
|
#
|
||||||
|
#-------------------------------------------------------------------%
|
||||||
|
|
||||||
PROJECT_NAME=libnazgul
|
PRJNAME=Libnazgul
|
||||||
TIMESTAMP:= $(shell date +"%Y-%m-%d_r%H%M")
|
GDATE:= $(shell date +"%Y-%m-%d_r%H%M")
|
||||||
ARCHIVE:= $(PROJECT_NAME)-$(TIMESTAMP).tar.bz2
|
GFILENAME:= $(PRJNAME)-$(GDATE).tar.bz2
|
||||||
|
PATH_GFILENAME:= ../$(GFILENAME)
|
||||||
|
GFILESIZE:=
|
||||||
LOCALDIR=$(shell pwd)
|
LOCALDIR=$(shell pwd)
|
||||||
|
LASTONSERVER = $(shell ssh glenux.ath.cx -l warbrain "ls -rt ~/Projet/Archives/$(PRJNAME)* | tail -n 1")
|
||||||
|
#MAILS=warbrain@glenux.ath.cx
|
||||||
|
#MAILS=glenuxian@airpost.net rolland@dptmaths.ens-cachan.fr el_shogun@netcourrier.com rolandgl@ufr-info-p7.jussieu.fr
|
||||||
|
|
||||||
all: subdir
|
all: subdir
|
||||||
|
|
||||||
run:
|
run:
|
||||||
( cd src/ ; \
|
( cd src/ ; \
|
||||||
|
@ -25,6 +50,20 @@ clean:
|
||||||
|
|
||||||
package: clean createpackage sendtoarchives
|
package: clean createpackage sendtoarchives
|
||||||
|
|
||||||
zip:
|
#mail: clean createpackage sendpackage sendtoarchives
|
||||||
tar -cjvf ../$(ARCHIVE) -C ../ $(PROJECT_NAME)
|
|
||||||
|
createpackage:
|
||||||
|
tar -cjvf $(PATH_GFILENAME) -C ../ $(PRJNAME)
|
||||||
|
|
||||||
|
sendtoarchives:
|
||||||
|
mv $(PATH_GFILENAME) ../Archives
|
||||||
|
|
||||||
|
#sendpackage:
|
||||||
|
# (echo -e "\nCi joint le fichier:\n$(shell du -sh $(PATH_GFILENAME))" \
|
||||||
|
# && echo -e "\nPour décompresser:" \
|
||||||
|
# && echo -e "\n\ttar -xjvf $(GFILENAME)\n" \
|
||||||
|
# && echo -e "\n(n'oubliez pas de supprimer l'ancien répertoire du même nom avant de décompresser)" \
|
||||||
|
# && echo -e "\n\nHistorique des modifications :\n" \
|
||||||
|
# && cat CHANGELOG ) \
|
||||||
|
# | mutt $(MAILS) -a $(PATH_GFILENAME) -s "[$(PRJNAME)] $(GDATE)"
|
||||||
|
|
||||||
|
|
19
README
19
README
|
@ -1,21 +1,22 @@
|
||||||
#-------------------------------------------------------------------%
|
#-------------------------------------------------------------------%
|
||||||
#
|
#
|
||||||
# LIBNAZGUL
|
# LIBNAZGUL : Library
|
||||||
#
|
#
|
||||||
#-------------------------------------------------------------------%
|
#-------------------------------------------------------------------%
|
||||||
#
|
#
|
||||||
# IUP GMI 2nd year,
|
# IUP GMI 2, Module de Système. 2003-2004.
|
||||||
# Project for the Operating Systems course,
|
# Cours de J-M. Rifflet.
|
||||||
# Classes by J-M. Rifflet, 2003-2004.
|
|
||||||
#
|
#
|
||||||
#-------------------------------------------------------------------%
|
#-------------------------------------------------------------------%
|
||||||
#
|
#
|
||||||
# Authors :
|
# Projet de :
|
||||||
#
|
# Glenn ROLLAND,
|
||||||
# Glenn ROLLAND
|
# Sebastian SCHAWOHL,
|
||||||
# Sebastian SCHAWOHL
|
# Rivka ZANA
|
||||||
# Rivka ZANA
|
|
||||||
#
|
#
|
||||||
|
# pour plus de détails au sujet du projet, voir le
|
||||||
|
# fichier README
|
||||||
|
#
|
||||||
#-------------------------------------------------------------------%
|
#-------------------------------------------------------------------%
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
\documentclass[12pt,a4paper]{report}
|
\documentclass[12pt,a4paper]{report}
|
||||||
%\usepackage{a4wide}
|
\usepackage{a4wide}
|
||||||
\usepackage{geometry}
|
\usepackage{geometry}
|
||||||
%\usepackage{typehtml}
|
\usepackage{typehtml}
|
||||||
\usepackage[latin1]{inputenc}
|
\usepackage[latin1]{inputenc}
|
||||||
%\usepackage{listings}
|
\usepackage{listings}
|
||||||
\usepackage[french]{babel}
|
\usepackage[french]{babel}
|
||||||
\usepackage{fancyheadings}
|
\usepackage{fancyheadings}
|
||||||
\usepackage{color}
|
\usepackage{color}
|
||||||
|
|
9
libnzg-sourceforge
Executable file
9
libnzg-sourceforge
Executable file
|
@ -0,0 +1,9 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
export CVS_RSH=ssh
|
||||||
|
export CVSROOT=:ext:login@cvs.tuxfamily.org:/cvsroot/libnazgul
|
||||||
|
|
||||||
|
# ci commit
|
||||||
|
# co new branch
|
||||||
|
# update
|
||||||
|
exec $SHELL
|
8
libnzg-ssh
Executable file
8
libnzg-ssh
Executable file
|
@ -0,0 +1,8 @@
|
||||||
|
#!/bin/sh
|
||||||
|
if [ -f .ssh-agent ]; then
|
||||||
|
. .ssh-agent
|
||||||
|
else
|
||||||
|
killall ssh-agent
|
||||||
|
ssh-agent > .ssh-agent
|
||||||
|
ssh-add ~/.ssh/id_rsa
|
||||||
|
fi
|
337
src/allocate.c
337
src/allocate.c
|
@ -9,33 +9,38 @@
|
||||||
|
|
||||||
/* TODO: prevoir le cas des négatifs dans la taille ... */
|
/* TODO: prevoir le cas des négatifs dans la taille ... */
|
||||||
|
|
||||||
void *msgAllocate(msgSpace * space, int pool, int taille, int option)
|
void * msgAllocate(msgSpace *space,
|
||||||
{
|
int pool,
|
||||||
void *resultAddr = NULL;
|
int taille,
|
||||||
int bufferFreeSize;
|
int option
|
||||||
int i;
|
){
|
||||||
msgPoolId resultPoolId;
|
void * resultAddr=NULL;
|
||||||
/* tableau des valeurs des semPoolCoef/pool pour identifier le pool
|
int bufferFreeSize;
|
||||||
* qui sera libéré le plus rapidement */
|
int i;
|
||||||
float semPoolCoef[space->poolNb];
|
msgPoolId resultPoolId;
|
||||||
int idxPoolOptimum;
|
/* tableau des valeurs des semPoolCoef/pool pour identifier le pool
|
||||||
bool gotRessourceSem;
|
* qui sera libéré le plus rapidement */
|
||||||
msgPoolDataTabSemId ressourceSemId;
|
float semPoolCoef[space->poolNb];
|
||||||
sem_t *ressourceSemFd;
|
int idxPoolOptimum;
|
||||||
int ressourceSemVal;
|
bool gotRessourceSem;
|
||||||
|
msgPoolDataTabSemId ressourceSemId;
|
||||||
|
sem_t * ressourceSemFd;
|
||||||
|
int ressourceSemVal;
|
||||||
int nbLockedSem;
|
int nbLockedSem;
|
||||||
float minPoolCoef;
|
float minPoolCoef;
|
||||||
int selectedPoolIndex;
|
int selectedPoolIndex;
|
||||||
int bufferFreeIndex;
|
int bufferFreeIndex;
|
||||||
msgPoolData *mSPoolDataTabAddr;
|
msgPoolData * mSPoolDataTabAddr;
|
||||||
|
|
||||||
|
|
||||||
selectedPoolIndex = -1;
|
selectedPoolIndex=-1;
|
||||||
|
|
||||||
mSPoolDataTabAddr = msgPoolDataTabOpen(space);
|
|
||||||
if (mSPoolDataTabAddr == NULL) {
|
mSPoolDataTabAddr=msgPoolDataTabOpen(space);
|
||||||
NZG_ERROR("msgPoolDataTabOpen", space->poolDataTabId);
|
if (mSPoolDataTabAddr==NULL){
|
||||||
goto ERROR;
|
NZG_ERROR("msgPoolDataTabOpen",space->poolDataTabId);
|
||||||
}
|
goto ERROR;
|
||||||
|
}
|
||||||
/*
|
/*
|
||||||
// verifier le premier arg du shm_open
|
// verifier le premier arg du shm_open
|
||||||
mSPoolDataTabFd=shm_open(space->poolDataTabId,
|
mSPoolDataTabFd=shm_open(space->poolDataTabId,
|
||||||
|
@ -59,167 +64,151 @@ void *msgAllocate(msgSpace * space, int pool, int taille, int option)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
gotRessourceSem = false;
|
gotRessourceSem=false;
|
||||||
|
|
||||||
/* initialisation des coefs */
|
/* initialisation des coefs */
|
||||||
for (i = 0; i < (space->poolNb); i++) {
|
for (i=0;i<(space->poolNb);i++){
|
||||||
semPoolCoef[i] = -1;
|
semPoolCoef[i]=-1;
|
||||||
}
|
}
|
||||||
|
|
||||||
nbLockedSem = 0;
|
nbLockedSem=0;
|
||||||
if (pool == ANYPOOL) {
|
if ( pool == ANYPOOL){
|
||||||
fprintf(stderr, "[ ALLOCATION ANYPOOL : %d ]\n", (int)getpid());
|
fprintf(stderr,"[ ALLOCATION ANYPOOL : %d ]\n",(int)getpid());
|
||||||
// choisir le pool au hasard (ou presque)
|
// choisir le pool au hasard (ou presque)
|
||||||
for (i = 0; i < (space->poolNb); i++) {
|
for(i=0; i<(space->poolNb); i++) {
|
||||||
printf("- boucle %d\n", i);
|
printf("- boucle %d\n",i); fflush(stdout);
|
||||||
fflush(stdout);
|
if(mSPoolDataTabAddr[i].bufferSize >= taille) {
|
||||||
if (mSPoolDataTabAddr[i].bufferSize >= taille) {
|
printf("( buffSize > taille )\n"); fflush(stdout);
|
||||||
printf("( buffSize > taille )\n");
|
/* choisir le numero du semaphore
|
||||||
fflush(stdout);
|
en fonction du nombre de lock poses / nombre de buffer */
|
||||||
/* choisir le numero du semaphore
|
msgPoolSemIdIntern(ressourceSemId,space->id,i);
|
||||||
en fonction du nombre de lock poses / nombre de buffer */
|
ressourceSemFd = sem_open(ressourceSemId,O_CREAT,SEM_DEFAULT_MODE,0);
|
||||||
msgPoolSemIdIntern(ressourceSemId, space->id,
|
if (ressourceSemFd == SEM_FAILED){
|
||||||
i);
|
NZG_ERROR("sem_open",ressourceSemId);
|
||||||
ressourceSemFd =
|
return NULL;
|
||||||
sem_open(ressourceSemId, O_CREAT,
|
|
||||||
SEM_DEFAULT_MODE, 0);
|
|
||||||
if (ressourceSemFd == SEM_FAILED) {
|
|
||||||
NZG_ERROR("sem_open", ressourceSemId);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
/* on remplit le tableau avec les valeurs des semaphores */
|
|
||||||
|
|
||||||
if (sem_getvalue
|
|
||||||
(ressourceSemFd, &ressourceSemVal) < 0) {
|
|
||||||
NZG_ERROR("sem_getvalue",
|
|
||||||
ressourceSemId);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
printf("RESSOURCESEMVAL %d\n", ressourceSemVal);
|
|
||||||
if (ressourceSemVal <= 0) {
|
|
||||||
printf("resVal < 0 : %d\n",
|
|
||||||
ressourceSemVal);
|
|
||||||
/* il y a ressourceSemVal processus qui attendent déja... */
|
|
||||||
semPoolCoef[nbLockedSem] =
|
|
||||||
(float)((1 -
|
|
||||||
ressourceSemVal) /
|
|
||||||
mSPoolDataTabAddr[i].
|
|
||||||
bufferNb);
|
|
||||||
nbLockedSem++;
|
|
||||||
}
|
|
||||||
if (sem_trywait(ressourceSemFd) == 0) {
|
|
||||||
printf("got try_wait\n");
|
|
||||||
/* choisir la 1ere pool de taille plus grande
|
|
||||||
* libre si possible */
|
|
||||||
gotRessourceSem = true;
|
|
||||||
selectedPoolIndex = i;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (sem_close(ressourceSemFd) < 0) {
|
|
||||||
NZG_ERROR("sem_getvalue",
|
|
||||||
ressourceSemId);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
} // if buffSize > taille
|
|
||||||
} // for
|
|
||||||
|
|
||||||
printf("ERRORDETECT outFor\n");
|
|
||||||
fflush(stdout);
|
|
||||||
|
|
||||||
if (!gotRessourceSem) {
|
|
||||||
printf("Calcul du meilleur en cas de liberation\n");
|
|
||||||
minPoolCoef = semPoolCoef[0];
|
|
||||||
idxPoolOptimum = 0;
|
|
||||||
/* on cherche le pool avec le moins de lock poses / nbre de buffer
|
|
||||||
* le numéro du pool est stocké dans idxPoolOptimum */
|
|
||||||
for (i = 0; i < nbLockedSem; i++) {
|
|
||||||
printf("Coef %d : %d\n", i,
|
|
||||||
(int)semPoolCoef[i]);
|
|
||||||
if ((semPoolCoef[i] != -1)
|
|
||||||
&& (semPoolCoef[i] < minPoolCoef)) {
|
|
||||||
minPoolCoef = semPoolCoef[i];
|
|
||||||
idxPoolOptimum = i;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (minPoolCoef == -1) {
|
|
||||||
/* il n'y a aucune pool dont la taille satisfait la demande */
|
|
||||||
return NULL;
|
|
||||||
} else {
|
|
||||||
selectedPoolIndex = idxPoolOptimum;
|
|
||||||
}
|
|
||||||
printf("Optimum : %d\n", selectedPoolIndex);
|
|
||||||
}
|
}
|
||||||
} else {
|
/* on remplit le tableau avec les valeurs des semaphores */
|
||||||
fprintf(stderr, "[ ALLOCATION : %d ]\n", (int)getpid());
|
|
||||||
selectedPoolIndex = pool;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!gotRessourceSem) {
|
if (sem_getvalue(ressourceSemFd, &ressourceSemVal) < 0){
|
||||||
msgPoolSemIdIntern(ressourceSemId, space->externId,
|
NZG_ERROR("sem_getvalue",ressourceSemId);
|
||||||
selectedPoolIndex);
|
return NULL;
|
||||||
ressourceSemFd =
|
|
||||||
sem_open(ressourceSemId, O_CREAT, SEM_DEFAULT_MODE, 0);
|
|
||||||
if (ressourceSemFd == SEM_FAILED) {
|
|
||||||
NZG_ERROR("sem_open", ressourceSemId);
|
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
//TODO:virer la ligne suivante:
|
printf("RESSOURCESEMVAL %d\n",ressourceSemVal);
|
||||||
sem_getvalue(ressourceSemFd, &ressourceSemVal);
|
if (ressourceSemVal <= 0){
|
||||||
|
printf("resVal < 0 : %d\n",ressourceSemVal);
|
||||||
printf("SemWait... %s : %d\n", ressourceSemId, ressourceSemVal);
|
/* il y a ressourceSemVal processus qui attendent déja... */
|
||||||
if (sem_wait(ressourceSemFd) < 0) {
|
semPoolCoef[nbLockedSem] =
|
||||||
NZG_ERROR("sem_wait", ressourceSemId);
|
(float) ((1-ressourceSemVal) / mSPoolDataTabAddr[i].bufferNb);
|
||||||
sem_close(ressourceSemFd);
|
nbLockedSem++;
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
printf("Passed %s\n", ressourceSemId);
|
if(sem_trywait(ressourceSemFd)==0) {
|
||||||
|
printf("got try_wait\n");
|
||||||
|
/* choisir la 1ere pool de taille plus grande
|
||||||
|
* libre si possible */
|
||||||
|
gotRessourceSem=true;
|
||||||
|
selectedPoolIndex=i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if( sem_close(ressourceSemFd) <0){
|
||||||
|
NZG_ERROR("sem_getvalue",ressourceSemId);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
} // if buffSize > taille
|
||||||
|
} // for
|
||||||
|
|
||||||
|
printf("ERRORDETECT outFor\n"); fflush(stdout);
|
||||||
|
|
||||||
|
if (!gotRessourceSem) {
|
||||||
|
printf("Calcul du meilleur en cas de liberation\n");
|
||||||
|
minPoolCoef= semPoolCoef[0];
|
||||||
|
idxPoolOptimum = 0;
|
||||||
|
/* on cherche le pool avec le moins de lock poses / nbre de buffer
|
||||||
|
* le numéro du pool est stocké dans idxPoolOptimum */
|
||||||
|
for(i=0; i<nbLockedSem; i++) {
|
||||||
|
printf("Coef %d : %d\n",i,(int)semPoolCoef[i]);
|
||||||
|
if ((semPoolCoef[i] != -1)
|
||||||
|
&& (semPoolCoef[i] < minPoolCoef)) {
|
||||||
|
minPoolCoef = semPoolCoef[i];
|
||||||
|
idxPoolOptimum = i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (minPoolCoef == -1){
|
||||||
|
/* il n'y a aucune pool dont la taille satisfait la demande */
|
||||||
|
return NULL;
|
||||||
|
} else {
|
||||||
|
selectedPoolIndex=idxPoolOptimum;
|
||||||
|
}
|
||||||
|
printf("Optimum : %d\n",selectedPoolIndex);
|
||||||
|
}
|
||||||
|
}else {
|
||||||
|
fprintf(stderr,"[ ALLOCATION : %d ]\n",(int)getpid());
|
||||||
|
selectedPoolIndex=pool;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!gotRessourceSem){
|
||||||
|
msgPoolSemIdIntern(ressourceSemId,space->externId,selectedPoolIndex);
|
||||||
|
ressourceSemFd=sem_open(ressourceSemId,O_CREAT,SEM_DEFAULT_MODE,0);
|
||||||
|
if(ressourceSemFd==SEM_FAILED){
|
||||||
|
NZG_ERROR("sem_open",ressourceSemId);
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* on a acqui un semaphore pour la ressouce */
|
//TODO:virer la ligne suivante:
|
||||||
/* on acquiert le droit de modifier les infos sur la ressource */
|
sem_getvalue(ressourceSemFd, &ressourceSemVal);
|
||||||
/* on protege le tableau des associations */
|
|
||||||
msgPoolDataTabLock(space);
|
printf("SemWait... %s : %d\n",ressourceSemId,ressourceSemVal);
|
||||||
|
if (sem_wait(ressourceSemFd) < 0){
|
||||||
|
NZG_ERROR("sem_wait",ressourceSemId);
|
||||||
|
sem_close(ressourceSemFd);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
printf("Passed %s\n",ressourceSemId);
|
||||||
|
}
|
||||||
|
|
||||||
/* on modifie maintenant les données */
|
|
||||||
/* - on récupere l'index du premier buffer libre */
|
/* on a acqui un semaphore pour la ressouce */
|
||||||
bufferFreeIndex =
|
/* on acquiert le droit de modifier les infos sur la ressource */
|
||||||
msgBufferGetFreeIndex(mSPoolDataTabAddr, selectedPoolIndex);
|
/* on protege le tableau des associations */
|
||||||
if (bufferFreeIndex < 0) {
|
msgPoolDataTabLock(space);
|
||||||
// aucun buffer libre ?
|
|
||||||
NZG_ERROR("msgBufferGetFreeIndex", "");
|
/* on modifie maintenant les données */
|
||||||
goto ERROR;
|
/* - on récupere l'index du premier buffer libre */
|
||||||
}
|
bufferFreeIndex = msgBufferGetFreeIndex(mSPoolDataTabAddr,selectedPoolIndex);
|
||||||
printf("Buffer selected : %d,%d\n", selectedPoolIndex, bufferFreeIndex);
|
if (bufferFreeIndex < 0){
|
||||||
/* mapper le buffer libre dans l'esp addr du proc */
|
// aucun buffer libre ?
|
||||||
strcpy(resultPoolId, mSPoolDataTabAddr[selectedPoolIndex].poolId);
|
NZG_ERROR("msgBufferGetFreeIndex","");
|
||||||
|
goto ERROR;
|
||||||
|
}
|
||||||
|
printf("Buffer selected : %d,%d\n",selectedPoolIndex,bufferFreeIndex);
|
||||||
|
/* mapper le buffer libre dans l'esp addr du proc */
|
||||||
|
strcpy(resultPoolId,mSPoolDataTabAddr[selectedPoolIndex].poolId);
|
||||||
|
|
||||||
bufferFreeSize = mSPoolDataTabAddr[selectedPoolIndex].bufferSize;
|
bufferFreeSize=mSPoolDataTabAddr[selectedPoolIndex].bufferSize;
|
||||||
printf("BufferSize : %d\n", bufferFreeSize);
|
printf("BufferSize : %d\n", bufferFreeSize);
|
||||||
|
|
||||||
|
resultAddr=msgBufferMap(mSPoolDataTabAddr,selectedPoolIndex,bufferFreeIndex);
|
||||||
|
if (resultAddr==NULL){
|
||||||
|
NZG_ERROR("msgBufferMap",mSPoolDataTabAddr[selectedPoolIndex].poolId);
|
||||||
|
goto ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
resultAddr =
|
/* - on s'enregistre aupres de ce buffer */
|
||||||
msgBufferMap(mSPoolDataTabAddr, selectedPoolIndex, bufferFreeIndex);
|
msgBufferAttachProc(mSPoolDataTabAddr,
|
||||||
if (resultAddr == NULL) {
|
selectedPoolIndex,
|
||||||
NZG_ERROR("msgBufferMap",
|
bufferFreeIndex,
|
||||||
mSPoolDataTabAddr[selectedPoolIndex].poolId);
|
resultAddr);
|
||||||
goto ERROR;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* - on s'enregistre aupres de ce buffer */
|
// munmap(mSPoolDataTabAddr,(space->poolNb) * sizeof( msgPoolData ));
|
||||||
msgBufferAttachProc(mSPoolDataTabAddr,
|
/* unmapper le msgPoolDataTab */
|
||||||
selectedPoolIndex, bufferFreeIndex, resultAddr);
|
msgPoolDataTabClose(space,mSPoolDataTabAddr);
|
||||||
|
msgPoolDataTabUnlock(space);
|
||||||
|
|
||||||
// munmap(mSPoolDataTabAddr,(space->poolNb) * sizeof( msgPoolData ));
|
printf( "alloc de 0x%08x\n", (int)resultAddr);
|
||||||
/* unmapper le msgPoolDataTab */
|
return resultAddr;
|
||||||
msgPoolDataTabClose(space, mSPoolDataTabAddr);
|
ERROR:
|
||||||
msgPoolDataTabUnlock(space);
|
NZG_ERROR("msgAllocate","error processing");
|
||||||
|
msgPoolDataTabUnlock(space);
|
||||||
printf("alloc de %p\n", (void *)resultAddr);
|
munmap(mSPoolDataTabAddr,(space->poolNb) * sizeof( msgPoolData ));
|
||||||
return resultAddr;
|
return NULL;
|
||||||
|
|
||||||
ERROR:
|
|
||||||
NZG_ERROR("msgAllocate", "error processing");
|
|
||||||
msgPoolDataTabUnlock(space);
|
|
||||||
munmap(mSPoolDataTabAddr, (space->poolNb) * sizeof(msgPoolData));
|
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
|
|
18
src/buffer.c
18
src/buffer.c
|
@ -1,11 +1,15 @@
|
||||||
#include "libnazgul.h"
|
#include "libnazgul.h"
|
||||||
|
|
||||||
int msgBufferGetAttachedProcIndex(msgPoolData * poolDataTabAddr,
|
int msgBufferGetAttachedProcIndex(
|
||||||
int poolIndex, void *addr)
|
msgPoolData * poolDataTabAddr,
|
||||||
{
|
int poolIndex,
|
||||||
|
void * addr
|
||||||
|
){
|
||||||
|
|
||||||
//TODO: parcourrir tous les index, et regarder s'il y
|
//TODO: parcourrir tous les index, et regarder s'il y
|
||||||
//a une addresse qui correspond avec le meme processus...
|
//a une addresse qui correspond avec le meme processus...
|
||||||
//et renvoyer l'index du buffer correspondant a l'addresse...
|
//et renvoyer l'index du buffer correspondant a l'addresse...
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,36 +1,41 @@
|
||||||
#include "libnazgul.h"
|
#include "libnazgul.h"
|
||||||
|
|
||||||
int msgBufferAttachProc(msgPoolData * poolDataTabAddr,
|
int msgBufferAttachProc(
|
||||||
int poolIndex, int bufferIndex, void *addr)
|
msgPoolData * poolDataTabAddr,
|
||||||
|
int poolIndex,
|
||||||
|
int bufferIndex,
|
||||||
|
void * addr)
|
||||||
{
|
{
|
||||||
msgBufferInfoTabId bufferInfoTabId;
|
msgBufferInfoTabId bufferInfoTabId;
|
||||||
int bufferInfoTabFd;
|
int bufferInfoTabFd;
|
||||||
msgBufferInfo *bufferInfoTabAddr;
|
msgBufferInfo * bufferInfoTabAddr;
|
||||||
int bufferInfoNb;
|
int bufferInfoNb;
|
||||||
|
|
||||||
//récuperer l'ID du BufferInfoTab;
|
//récuperer l'ID du BufferInfoTab;
|
||||||
strcpy(bufferInfoTabId, poolDataTabAddr[poolIndex].bufferInfoTabId);
|
strcpy(bufferInfoTabId, poolDataTabAddr[poolIndex].bufferInfoTabId);
|
||||||
|
|
||||||
bufferInfoTabFd = shm_open(bufferInfoTabId, O_RDWR, SHM_DEFAULT_MODE);
|
|
||||||
if (bufferInfoTabFd < 0) {
|
bufferInfoTabFd=shm_open(bufferInfoTabId,O_RDWR,SHM_DEFAULT_MODE);
|
||||||
NZG_ERROR("sem_open", bufferInfoTabId);
|
if (bufferInfoTabFd<0){
|
||||||
return -1;
|
NZG_ERROR("sem_open",bufferInfoTabId);
|
||||||
}
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
/** on regarde dans le tableau d'infos de buffer **/
|
/** on regarde dans le tableau d'infos de buffer **/
|
||||||
bufferInfoNb = poolDataTabAddr[poolIndex].bufferNb;
|
bufferInfoNb=poolDataTabAddr[poolIndex].bufferNb;
|
||||||
bufferInfoTabAddr = mmap(NULL, bufferInfoNb * sizeof(msgBufferInfo),
|
bufferInfoTabAddr=mmap(NULL,bufferInfoNb*sizeof(msgBufferInfo),
|
||||||
PROT_READ | PROT_WRITE, MAP_SHARED,
|
PROT_READ|PROT_WRITE,MAP_SHARED,bufferInfoTabFd,(off_t)0);
|
||||||
bufferInfoTabFd, (off_t) 0);
|
printf("atta gooo %s\n",bufferInfoTabId);
|
||||||
printf("atta gooo %s\n", bufferInfoTabId);
|
|
||||||
|
|
||||||
bufferInfoTabAddr[bufferIndex].ownerPid = getpid();
|
bufferInfoTabAddr[bufferIndex].ownerPid = getpid();
|
||||||
bufferInfoTabAddr[bufferIndex].addr = addr;
|
bufferInfoTabAddr[bufferIndex].addr = addr;
|
||||||
|
|
||||||
if (munmap(bufferInfoTabAddr, bufferInfoNb * sizeof(msgBufferInfo)) < 0) {
|
if (munmap(bufferInfoTabAddr,bufferInfoNb*sizeof(msgBufferInfo))< 0)
|
||||||
NZG_ERROR("munmap", bufferInfoTabId);
|
{
|
||||||
return -1;
|
NZG_ERROR("munmap",bufferInfoTabId);
|
||||||
}
|
return -1; }
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,37 +1,42 @@
|
||||||
#include "libnazgul.h"
|
#include "libnazgul.h"
|
||||||
|
|
||||||
int msgBufferDetachProc(msgPoolData * poolDataTabAddr,
|
int msgBufferDetachProc(
|
||||||
int poolIndex, int bufferIndex, void *addr)
|
msgPoolData * poolDataTabAddr,
|
||||||
{
|
int poolIndex,
|
||||||
msgBufferInfoTabId bufferInfoTabId;
|
int bufferIndex,
|
||||||
int bufferInfoTabFd;
|
void * addr
|
||||||
msgBufferInfo *bufferInfoTabAddr;
|
){
|
||||||
int bufferInfoNb;
|
msgBufferInfoTabId bufferInfoTabId;
|
||||||
|
int bufferInfoTabFd;
|
||||||
|
msgBufferInfo * bufferInfoTabAddr;
|
||||||
|
int bufferInfoNb;
|
||||||
|
|
||||||
printf("Detaching %d,%d\n", poolIndex, bufferIndex);
|
printf("Detaching %d,%d\n",poolIndex,bufferIndex);
|
||||||
//récuperer l'ID du BufferInfoTab;
|
//récuperer l'ID du BufferInfoTab;
|
||||||
|
|
||||||
strcpy(bufferInfoTabId, poolDataTabAddr[poolIndex].bufferInfoTabId);
|
|
||||||
|
|
||||||
bufferInfoTabFd = shm_open(bufferInfoTabId, O_RDWR, SHM_DEFAULT_MODE);
|
strcpy(bufferInfoTabId, poolDataTabAddr[poolIndex].bufferInfoTabId);
|
||||||
if (bufferInfoTabFd < 0) {
|
|
||||||
NZG_ERROR("shm_open", bufferInfoTabId);
|
bufferInfoTabFd=shm_open(bufferInfoTabId,O_RDWR,SHM_DEFAULT_MODE);
|
||||||
return -1;
|
if (bufferInfoTabFd<0){
|
||||||
}
|
NZG_ERROR("shm_open",bufferInfoTabId);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
/** on regarde dans le tableau d'infos de buffer **/
|
/** on regarde dans le tableau d'infos de buffer **/
|
||||||
bufferInfoNb = poolDataTabAddr[poolIndex].bufferNb;
|
bufferInfoNb=poolDataTabAddr[poolIndex].bufferNb;
|
||||||
bufferInfoTabAddr = mmap(NULL, bufferInfoNb * sizeof(msgBufferInfo),
|
bufferInfoTabAddr=mmap(NULL,bufferInfoNb*sizeof(msgBufferInfo),
|
||||||
PROT_READ | PROT_WRITE, MAP_SHARED,
|
PROT_READ|PROT_WRITE,MAP_SHARED,bufferInfoTabFd,(off_t)0);
|
||||||
bufferInfoTabFd, (off_t) 0);
|
|
||||||
|
|
||||||
bufferInfoTabAddr[bufferIndex].ownerPid = (pid_t) - 1;
|
bufferInfoTabAddr[bufferIndex].ownerPid = (pid_t)-1;
|
||||||
bufferInfoTabAddr[bufferIndex].addr = NULL;
|
bufferInfoTabAddr[bufferIndex].addr = NULL;
|
||||||
|
|
||||||
if (munmap(bufferInfoTabAddr, bufferInfoNb * sizeof(msgBufferInfo)) < 0) {
|
if (munmap(bufferInfoTabAddr,bufferInfoNb*sizeof(msgBufferInfo))< 0)
|
||||||
NZG_ERROR("munmap", bufferInfoTabId);
|
{
|
||||||
return -1;
|
NZG_ERROR("munmap",bufferInfoTabId);
|
||||||
}
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,43 +1,39 @@
|
||||||
#include "libnazgul.h"
|
#include "libnazgul.h"
|
||||||
|
|
||||||
int msgBufferGetFreeIndex(msgPoolData * poolDataTabAddr, int poolIndex)
|
int msgBufferGetFreeIndex(msgPoolData * poolDataTabAddr,int poolIndex){
|
||||||
{
|
msgBufferInfoTabId bufferInfoTabId;
|
||||||
msgBufferInfoTabId bufferInfoTabId;
|
int bufferInfoTabFd;
|
||||||
int bufferInfoTabFd;
|
msgBufferInfo * bufferInfoTabAddr;
|
||||||
msgBufferInfo *bufferInfoTabAddr;
|
int bufferInfoNb;
|
||||||
int bufferInfoNb;
|
int bufferFreeIndex;
|
||||||
int bufferFreeIndex;
|
int i;
|
||||||
int i;
|
|
||||||
|
|
||||||
//récuperer l'ID du BufferInfoTab;
|
//récuperer l'ID du BufferInfoTab;
|
||||||
strcpy(bufferInfoTabId, poolDataTabAddr[poolIndex].bufferInfoTabId);
|
strcpy(bufferInfoTabId, poolDataTabAddr[poolIndex].bufferInfoTabId);
|
||||||
|
|
||||||
bufferInfoTabFd = shm_open(bufferInfoTabId, O_RDWR, SHM_DEFAULT_MODE);
|
bufferInfoTabFd=shm_open(bufferInfoTabId,O_RDWR,SHM_DEFAULT_MODE);
|
||||||
if (bufferInfoTabFd < 0) {
|
if (bufferInfoTabFd<0){
|
||||||
NZG_ERROR("shm_open", bufferInfoTabId);
|
NZG_ERROR("shm_open",bufferInfoTabId);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** on regarde dans le tableau d'infos de buffer **/
|
/** on regarde dans le tableau d'infos de buffer **/
|
||||||
bufferInfoNb = poolDataTabAddr[poolIndex].bufferNb;
|
bufferInfoNb=poolDataTabAddr[poolIndex].bufferNb;
|
||||||
bufferInfoTabAddr = mmap(NULL, bufferInfoNb * sizeof(msgBufferInfo),
|
bufferInfoTabAddr=mmap(NULL,bufferInfoNb*sizeof(msgBufferInfo),
|
||||||
PROT_READ, MAP_SHARED, bufferInfoTabFd,
|
PROT_READ,MAP_SHARED,bufferInfoTabFd,(off_t)0);
|
||||||
(off_t) 0);
|
|
||||||
|
|
||||||
i = 0;
|
i=0;
|
||||||
while ((i < bufferInfoNb)
|
while ((i<bufferInfoNb)
|
||||||
&& (bufferInfoTabAddr[i].ownerPid != (pid_t) - 1)) {
|
&& (bufferInfoTabAddr[i].ownerPid != (pid_t)-1)){ i++; }
|
||||||
i++;
|
if (i == bufferInfoNb){ return -1; }
|
||||||
}
|
bufferFreeIndex=i;
|
||||||
if (i == bufferInfoNb) {
|
|
||||||
return -1;
|
if (munmap(bufferInfoTabAddr,bufferInfoNb*sizeof(msgBufferInfo))< 0)
|
||||||
}
|
{
|
||||||
bufferFreeIndex = i;
|
NZG_ERROR("munmap",bufferInfoTabId);
|
||||||
|
return -1;
|
||||||
if (munmap(bufferInfoTabAddr, bufferInfoNb * sizeof(msgBufferInfo)) < 0) {
|
}
|
||||||
NZG_ERROR("munmap", bufferInfoTabId);
|
|
||||||
return -1;
|
return bufferFreeIndex;
|
||||||
}
|
|
||||||
|
|
||||||
return bufferFreeIndex;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,61 +1,51 @@
|
||||||
#include "libnazgul.h"
|
#include "libnazgul.h"
|
||||||
|
|
||||||
int msgBufferGetProcAttach(msgPoolData * poolDataTabAddr,
|
int msgBufferGetProcAttach(
|
||||||
int poolNb,
|
msgPoolData * poolDataTabAddr,
|
||||||
int *poolIndex, int *bufferIndex, void *addr)
|
int poolNb,
|
||||||
{
|
int * poolIndex,
|
||||||
msgBufferInfoTabId bufferInfoTabId;
|
int * bufferIndex,
|
||||||
int bufferInfoTabFd;
|
void * addr
|
||||||
msgBufferInfo *bufferInfoTabAddr;
|
){
|
||||||
int bufferInfoNb;
|
msgBufferInfoTabId bufferInfoTabId;
|
||||||
|
int bufferInfoTabFd;
|
||||||
|
msgBufferInfo * bufferInfoTabAddr;
|
||||||
|
int bufferInfoNb;
|
||||||
|
|
||||||
bool found = false;
|
bool found=false;
|
||||||
int pIdx = 0;
|
int pIdx=0;
|
||||||
int bIdx;
|
int bIdx;
|
||||||
while ((!found) && (pIdx < poolNb)) {
|
while ((!found) && (pIdx < poolNb)){
|
||||||
/* Pour chaque pool */
|
/* Pour chaque pool */
|
||||||
//récuperer l'ID du BufferInfoTab;
|
//récuperer l'ID du BufferInfoTab;
|
||||||
strcpy(bufferInfoTabId, poolDataTabAddr[pIdx].bufferInfoTabId);
|
strcpy(bufferInfoTabId, poolDataTabAddr[pIdx].bufferInfoTabId);
|
||||||
bufferInfoNb = poolDataTabAddr[pIdx].bufferNb;
|
bufferInfoNb=poolDataTabAddr[pIdx].bufferNb;
|
||||||
|
|
||||||
bufferInfoTabFd =
|
bufferInfoTabFd=shm_open(bufferInfoTabId,O_RDWR,SHM_DEFAULT_MODE);
|
||||||
shm_open(bufferInfoTabId, O_RDWR, SHM_DEFAULT_MODE);
|
if (bufferInfoTabFd<0)
|
||||||
if (bufferInfoTabFd < 0) {
|
{ NZG_ERROR("shm_open",bufferInfoTabId); return -1; }
|
||||||
NZG_ERROR("shm_open", bufferInfoTabId);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** on regarde dans le tableau d'infos de buffer **/
|
/** on regarde dans le tableau d'infos de buffer **/
|
||||||
bufferInfoTabAddr =
|
bufferInfoTabAddr=mmap(NULL,bufferInfoNb*sizeof(msgBufferInfo),
|
||||||
mmap(NULL, bufferInfoNb * sizeof(msgBufferInfo), PROT_READ,
|
PROT_READ,MAP_SHARED,bufferInfoTabFd,(off_t)0);
|
||||||
MAP_SHARED, bufferInfoTabFd, (off_t) 0);
|
|
||||||
|
|
||||||
/* on cherche dans chacun des buffers */
|
/* on cherche dans chacun des buffers */
|
||||||
bIdx = 0;
|
bIdx=0;
|
||||||
while ((!found) && bIdx < bufferInfoNb) {
|
while((!found) && bIdx<bufferInfoNb){
|
||||||
if (bufferInfoTabAddr[bIdx].addr == addr) {
|
if (bufferInfoTabAddr[bIdx].addr == addr){
|
||||||
found = true;
|
found=true;
|
||||||
(*bufferIndex) = bIdx;
|
(*bufferIndex)=bIdx;
|
||||||
};
|
};
|
||||||
bIdx++;
|
bIdx++;
|
||||||
}
|
|
||||||
if (found) {
|
|
||||||
(*poolIndex) = pIdx;
|
|
||||||
}
|
|
||||||
/* on détache le morceau de mémoire */
|
|
||||||
if (munmap
|
|
||||||
(bufferInfoTabAddr,
|
|
||||||
bufferInfoNb * sizeof(msgBufferInfo)) < 0) {
|
|
||||||
NZG_ERROR("munmap", bufferInfoTabId);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
close(bufferInfoTabFd);
|
|
||||||
pIdx++;
|
|
||||||
}
|
}
|
||||||
|
if (found){ (*poolIndex)=pIdx; }
|
||||||
|
/* on détache le morceau de mémoire */
|
||||||
|
if (munmap(bufferInfoTabAddr,bufferInfoNb*sizeof(msgBufferInfo))< 0)
|
||||||
|
{ NZG_ERROR("munmap",bufferInfoTabId); return -1; }
|
||||||
|
close(bufferInfoTabFd);
|
||||||
|
pIdx++;
|
||||||
|
}
|
||||||
|
|
||||||
if (found) {
|
if (found){ return 0; } else {return -1;}
|
||||||
return 0;
|
|
||||||
} else {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,39 +1,37 @@
|
||||||
#include "libnazgul.h"
|
#include "libnazgul.h"
|
||||||
#include "ids.h"
|
#include "ids.h"
|
||||||
|
|
||||||
int msgBufferInfoTabCreate(msgSpaceId externId,
|
int msgBufferInfoTabCreate(
|
||||||
msgPoolData * poolDataTabAddr,
|
msgSpaceId externId,
|
||||||
int poolIdx, int bufferNb)
|
msgPoolData * poolDataTabAddr,
|
||||||
{
|
int poolIdx,
|
||||||
|
int bufferNb) {
|
||||||
|
|
||||||
int bufferInfoTabFd;
|
int bufferInfoTabFd;
|
||||||
msgBufferInfoTabId bufferInfoTabId;
|
msgBufferInfoTabId bufferInfoTabId;
|
||||||
|
|
||||||
/* creation des infos sur buffers DEBUT */
|
|
||||||
if (msgBufferInfoTabIdIntern(bufferInfoTabId, externId, poolIdx) == -1) {
|
|
||||||
NZG_ERROR("msgPoolId creation", bufferInfoTabId);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
bufferInfoTabFd =
|
|
||||||
shm_open(bufferInfoTabId, O_RDWR | O_CREAT | O_EXCL | O_TRUNC,
|
|
||||||
MSGSPACE_DEFAULT_MODE);
|
|
||||||
if (bufferInfoTabFd == -1) {
|
|
||||||
fprintf(stderr, "msgInfoTab : %s creation failed: %s\n",
|
|
||||||
bufferInfoTabId, strerror(errno));
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
if (ftruncate(bufferInfoTabFd, bufferNb * sizeof(msgBufferInfo)) == -1) {
|
|
||||||
fprintf(stderr, "msgBufferInfoTab resizing failed: %s\n",
|
|
||||||
strerror(errno));
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
close(bufferInfoTabFd);
|
|
||||||
/* creation des infos sur buffers FIN */
|
|
||||||
|
|
||||||
msgBufferInfoTabInit(poolDataTabAddr, poolIdx);
|
|
||||||
|
|
||||||
|
/* creation des infos sur buffers DEBUT */
|
||||||
|
if (msgBufferInfoTabIdIntern(bufferInfoTabId,externId,poolIdx) == -1){
|
||||||
|
NZG_ERROR("msgPoolId creation",bufferInfoTabId);
|
||||||
return -1;
|
return -1;
|
||||||
NZG_ERROR("munmap", bufferInfoTabId);
|
}
|
||||||
|
|
||||||
|
bufferInfoTabFd=shm_open(bufferInfoTabId,O_RDWR|O_CREAT|O_EXCL|O_TRUNC,MSGSPACE_DEFAULT_MODE);
|
||||||
|
if (bufferInfoTabFd == -1 ) {
|
||||||
|
fprintf( stderr, "msgInfoTab : %s creation failed: %s\n",bufferInfoTabId,
|
||||||
|
strerror( errno ) );
|
||||||
return -1;
|
return -1;
|
||||||
|
}
|
||||||
|
if (ftruncate(bufferInfoTabFd, bufferNb*sizeof(msgBufferInfo)) == -1){
|
||||||
|
fprintf( stderr, "msgBufferInfoTab resizing failed: %s\n",
|
||||||
|
strerror( errno ) );
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
close(bufferInfoTabFd);
|
||||||
|
/* creation des infos sur buffers FIN */
|
||||||
|
|
||||||
|
msgBufferInfoTabInit(poolDataTabAddr,poolIdx);
|
||||||
|
|
||||||
|
return -1;NZG_ERROR("munmap",bufferInfoTabId);
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,38 +1,34 @@
|
||||||
#include "libnazgul.h"
|
#include "libnazgul.h"
|
||||||
|
|
||||||
int msgBufferInfoTabInit(msgPoolData * poolDataTabAddr, int poolIndex)
|
int msgBufferInfoTabInit(msgPoolData * poolDataTabAddr,int poolIndex){
|
||||||
{
|
msgBufferInfoTabId bufferInfoTabId;
|
||||||
msgBufferInfoTabId bufferInfoTabId;
|
int bufferInfoTabFd;
|
||||||
int bufferInfoTabFd;
|
msgBufferInfo * bufferInfoTabAddr;
|
||||||
msgBufferInfo *bufferInfoTabAddr;
|
int bufferInfoNb;
|
||||||
int bufferInfoNb;
|
int i;
|
||||||
int i;
|
|
||||||
|
|
||||||
//récuperer l'ID du BufferInfoTab;
|
//récuperer l'ID du BufferInfoTab;
|
||||||
strcpy(bufferInfoTabId, poolDataTabAddr[poolIndex].bufferInfoTabId);
|
strcpy(bufferInfoTabId, poolDataTabAddr[poolIndex].bufferInfoTabId);
|
||||||
|
|
||||||
printf("msgBufferInfoTabId %d open >>%s<<\n", poolIndex,
|
printf("msgBufferInfoTabId %d open >>%s<<\n",poolIndex,bufferInfoTabId);
|
||||||
bufferInfoTabId);
|
bufferInfoTabFd=shm_open(bufferInfoTabId,O_RDWR,SHM_DEFAULT_MODE);
|
||||||
bufferInfoTabFd = shm_open(bufferInfoTabId, O_RDWR, SHM_DEFAULT_MODE);
|
if (bufferInfoTabFd<0){
|
||||||
if (bufferInfoTabFd < 0) {
|
NZG_ERROR("msgBufferInfoTabId open",bufferInfoTabId);
|
||||||
NZG_ERROR("msgBufferInfoTabId open", bufferInfoTabId);
|
return -1;
|
||||||
return -1;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/** on regarde dans le tableau d'infos de buffer **/
|
/** on regarde dans le tableau d'infos de buffer **/
|
||||||
bufferInfoNb = poolDataTabAddr[poolIndex].bufferNb;
|
bufferInfoNb=poolDataTabAddr[poolIndex].bufferNb;
|
||||||
bufferInfoTabAddr = mmap(NULL, bufferInfoNb * sizeof(msgBufferInfo),
|
bufferInfoTabAddr=mmap(NULL,bufferInfoNb*sizeof(msgBufferInfo),
|
||||||
PROT_WRITE | PROT_READ, MAP_SHARED,
|
PROT_WRITE|PROT_READ,MAP_SHARED,bufferInfoTabFd,(off_t)0);
|
||||||
bufferInfoTabFd, (off_t) 0);
|
|
||||||
|
|
||||||
for (i = 0; i < bufferInfoNb; i++) {
|
for (i=0;i<bufferInfoNb;i++){
|
||||||
bufferInfoTabAddr[i].ownerPid = (pid_t) - 1;
|
bufferInfoTabAddr[i].ownerPid = (pid_t)-1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (munmap(bufferInfoTabAddr,bufferInfoNb*sizeof(msgBufferInfo))< 0)
|
||||||
|
{ perror("munmap"); return -1; }
|
||||||
|
|
||||||
if (munmap(bufferInfoTabAddr, bufferInfoNb * sizeof(msgBufferInfo)) < 0) {
|
return 0;
|
||||||
perror("munmap");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,50 +1,52 @@
|
||||||
#include "libnazgul.h"
|
#include "libnazgul.h"
|
||||||
|
|
||||||
void *msgBufferMap(msgPoolData * poolDataTab, int poolIndex, int bufferIndex)
|
|
||||||
{
|
|
||||||
void *resultAddr;
|
|
||||||
int bufferSize, bufferNb;
|
|
||||||
int poolBufferTabFd;
|
|
||||||
msgPoolId poolBufferTabId;
|
|
||||||
printf("Mapping buffer (%d,%d)\n", poolIndex, bufferIndex);
|
|
||||||
// TODO: récuperer l'ID du BufferInfoTab;
|
|
||||||
strcpy(poolBufferTabId, poolDataTab[poolIndex].poolId);
|
|
||||||
bufferSize = poolDataTab[poolIndex].bufferSize;
|
|
||||||
bufferNb = poolDataTab[poolIndex].bufferNb;
|
|
||||||
if (bufferNb < 0) {
|
|
||||||
// do something with bufferNb
|
|
||||||
}
|
|
||||||
|
|
||||||
poolBufferTabFd = shm_open(poolBufferTabId, O_RDWR, SHM_DEFAULT_MODE);
|
void * msgBufferMap(msgPoolData * poolDataTab, int poolIndex, int bufferIndex) {
|
||||||
if (poolBufferTabFd < 0) {
|
void * resultAddr;
|
||||||
NZG_ERROR("shm_open", poolBufferTabId);
|
int bufferSize, bufferNb;
|
||||||
goto ERROR;
|
int poolBufferTabFd;
|
||||||
}
|
msgPoolId poolBufferTabId;
|
||||||
// mapper le buffer dans l'espace mémoire du processus
|
printf("Mapping buffer (%d,%d)\n",poolIndex,bufferIndex);
|
||||||
/* on s'arrete juste derriere l'index qui nous intéresse */
|
// TODO: récuperer l'ID du BufferInfoTab;
|
||||||
resultAddr = mmap(NULL, bufferSize * (bufferIndex + 1), PROT_READ | PROT_WRITE, //PROT_NONE
|
strcpy(poolBufferTabId, poolDataTab[poolIndex].poolId);
|
||||||
MAP_SHARED, poolBufferTabFd, (off_t) 0);
|
bufferSize=poolDataTab[poolIndex].bufferSize;
|
||||||
if (resultAddr == MAP_FAILED) {
|
bufferNb=poolDataTab[poolIndex].bufferNb;
|
||||||
NZG_ERROR("mmap", poolBufferTabId);
|
|
||||||
goto ERROR;
|
|
||||||
}
|
|
||||||
printf("Mapped from %p to %p\n",
|
|
||||||
(void *)resultAddr,
|
|
||||||
(void *)(resultAddr + bufferSize * (bufferIndex + 1))
|
|
||||||
);
|
|
||||||
|
|
||||||
resultAddr = resultAddr + (bufferSize * bufferIndex);
|
poolBufferTabFd=shm_open(poolBufferTabId,O_RDWR,SHM_DEFAULT_MODE);
|
||||||
printf("Moved to %p\n", (void *)resultAddr);
|
if (poolBufferTabFd<0){
|
||||||
|
NZG_ERROR("shm_open",poolBufferTabId);
|
||||||
|
goto ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
/* mprotect(
|
// mapper le buffer dans l'espace mémoire du processus
|
||||||
resultAddr,
|
/* on s'arrete juste derriere l'index qui nous intéresse */
|
||||||
bufferSize,
|
resultAddr=mmap(NULL,
|
||||||
PROT_READ|PROT_WRITE
|
bufferSize*(bufferIndex+1),
|
||||||
); */
|
PROT_READ|PROT_WRITE, //PROT_NONE
|
||||||
|
MAP_SHARED,
|
||||||
|
poolBufferTabFd,
|
||||||
|
(off_t)0);
|
||||||
|
if(resultAddr == MAP_FAILED) {
|
||||||
|
NZG_ERROR("mmap", poolBufferTabId);
|
||||||
|
goto ERROR;
|
||||||
|
}
|
||||||
|
printf( "Mapped from 0x%08x to 0x%08x\n",
|
||||||
|
(int)resultAddr,
|
||||||
|
(int)resultAddr+ bufferSize*(bufferIndex+1)
|
||||||
|
);
|
||||||
|
|
||||||
close(poolBufferTabFd);
|
resultAddr=resultAddr +( bufferSize*bufferIndex);
|
||||||
|
printf( "Moved to 0x%08x\n",(int)resultAddr );
|
||||||
|
|
||||||
return resultAddr;
|
/* mprotect(
|
||||||
ERROR:
|
resultAddr,
|
||||||
return NULL;
|
bufferSize,
|
||||||
|
PROT_READ|PROT_WRITE
|
||||||
|
);*/
|
||||||
|
|
||||||
|
close(poolBufferTabFd);
|
||||||
|
|
||||||
|
return resultAddr;
|
||||||
|
ERROR:
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
103
src/free.c
103
src/free.c
|
@ -1,63 +1,66 @@
|
||||||
#include "libnazgul.h"
|
#include "libnazgul.h"
|
||||||
|
|
||||||
int msgFree(msgSpace * space, void *addr)
|
int msgFree(msgSpace * space, void * addr){
|
||||||
{
|
|
||||||
|
|
||||||
int poolIndex;
|
int poolIndex;
|
||||||
int bufferIndex;
|
int bufferIndex;
|
||||||
msgPoolData *poolDataTabAddr;
|
msgPoolData * poolDataTabAddr;
|
||||||
sem_t *ressourceSemFd;
|
sem_t * ressourceSemFd;
|
||||||
msgPoolDataTabSemId ressourceSemId;
|
msgPoolDataTabSemId ressourceSemId;
|
||||||
int err;
|
int err;
|
||||||
int bufferNb;
|
int bufferNb;
|
||||||
int bufferSize;
|
int bufferSize;
|
||||||
void *realAddr;
|
void * realAddr;
|
||||||
printf("[ FREE %p ]\n", (void *)addr);
|
printf("[ FREE 0x%08x ]\n",(int)addr);
|
||||||
/* on acquiert le droit de modifier les infos sur la ressource */
|
/* on acquiert le droit de modifier les infos sur la ressource */
|
||||||
/* on protege le tableau des associations */
|
/* on protege le tableau des associations */
|
||||||
if (msgPoolDataTabLock(space) < 0) {
|
if (msgPoolDataTabLock(space) <0){
|
||||||
NZG_ERROR("msgPoolDataTabLock", space->poolDataTabSemId);
|
NZG_ERROR("msgPoolDataTabLock",space->poolDataTabSemId);
|
||||||
goto ERROR;
|
goto ERROR;
|
||||||
};
|
};
|
||||||
|
|
||||||
/* verifier le premier arg du shm_open */
|
/* verifier le premier arg du shm_open */
|
||||||
|
|
||||||
poolDataTabAddr = msgPoolDataTabOpen(space);
|
poolDataTabAddr = msgPoolDataTabOpen(space);
|
||||||
|
|
||||||
// TODO: verouiller semaphore DataInfo ??
|
// TODO: verouiller semaphore DataInfo ??
|
||||||
|
|
||||||
poolIndex = -1;
|
poolIndex=-1; bufferIndex=-1;
|
||||||
bufferIndex = -1;
|
err=msgBufferGetProcAttach(
|
||||||
err = msgBufferGetProcAttach(poolDataTabAddr,
|
poolDataTabAddr,
|
||||||
space->poolNb,
|
space->poolNb,
|
||||||
&poolIndex, &bufferIndex, addr);
|
&poolIndex,
|
||||||
|
&bufferIndex,
|
||||||
|
addr
|
||||||
|
);
|
||||||
|
|
||||||
printf("Found : %d\n", err);
|
printf("Found : %d\n",err);
|
||||||
printf("Freing pool: %d, buffer: %d\n", poolIndex, bufferIndex);
|
printf("Freing pool: %d, buffer: %d\n",poolIndex,bufferIndex);
|
||||||
msgBufferDetachProc(poolDataTabAddr, poolIndex, bufferIndex, addr);
|
msgBufferDetachProc(poolDataTabAddr,poolIndex,bufferIndex,addr);
|
||||||
|
|
||||||
/* unmapper le buffer */
|
/* unmapper le buffer */
|
||||||
realAddr = addr;
|
realAddr=addr;
|
||||||
bufferSize = poolDataTabAddr[poolIndex].bufferSize;
|
bufferSize=poolDataTabAddr[poolIndex].bufferSize;
|
||||||
bufferNb = poolDataTabAddr[poolIndex].bufferNb;
|
bufferNb=poolDataTabAddr[poolIndex].bufferNb;
|
||||||
realAddr = realAddr - poolIndex * bufferSize;
|
realAddr=realAddr-poolIndex*bufferSize;
|
||||||
munmap(realAddr, bufferSize * bufferNb);
|
munmap(realAddr,bufferSize*bufferNb);
|
||||||
|
|
||||||
msgPoolDataTabClose(space, poolDataTabAddr);
|
msgPoolDataTabClose(space,poolDataTabAddr);
|
||||||
|
|
||||||
// deverouiller semaphore DataInfo
|
// deverouiller semaphore DataInfo
|
||||||
msgPoolDataTabUnlock(space);
|
msgPoolDataTabUnlock(space);
|
||||||
|
|
||||||
// deverouiller semaphore ressource.
|
// deverouiller semaphore ressource.
|
||||||
msgPoolSemIdIntern(ressourceSemId, space->externId, poolIndex);
|
msgPoolSemIdIntern(ressourceSemId,space->externId,poolIndex);
|
||||||
ressourceSemFd = sem_open(ressourceSemId, O_CREAT, SEM_DEFAULT_MODE, 0);
|
ressourceSemFd = sem_open(ressourceSemId,O_CREAT,SEM_DEFAULT_MODE,0);
|
||||||
if (ressourceSemFd == SEM_FAILED) {
|
if (ressourceSemFd == SEM_FAILED){
|
||||||
NZG_ERROR("sem_open", ressourceSemId);
|
NZG_ERROR("sem_open",ressourceSemId);
|
||||||
goto ERROR;
|
goto ERROR;
|
||||||
}
|
}
|
||||||
sem_post(ressourceSemFd);
|
sem_post(ressourceSemFd);
|
||||||
sem_close(ressourceSemFd);
|
sem_close(ressourceSemFd);
|
||||||
return 0;
|
return 0;
|
||||||
ERROR:
|
ERROR:
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
117
src/get.c
117
src/get.c
|
@ -2,71 +2,70 @@
|
||||||
|
|
||||||
#define NONBLOCK -1
|
#define NONBLOCK -1
|
||||||
|
|
||||||
void *msgGet(msgSpace * space, int queueIndex, int option)
|
void * msgGet(msgSpace * space,int queueIndex,int option){
|
||||||
{
|
void * resultAddr;
|
||||||
void *resultAddr;
|
msgQueueId queueId;
|
||||||
msgQueueId queueId;
|
msgQueue * queue;
|
||||||
msgQueue *queue;
|
msgQueueElemId oldElemId;
|
||||||
msgQueueElemId oldElemId;
|
msgQueueElem * oldElem;
|
||||||
msgQueueElem *oldElem;
|
msgPoolData * poolDataTab;
|
||||||
msgPoolData *poolDataTab;
|
// on teste la possibilité de lecture sur la liste...
|
||||||
// on teste la possibilité de lecture sur la liste...
|
if (option == NONBLOCK){
|
||||||
if (option == NONBLOCK) {
|
if (msgQueueReadTryLock(space->externId,queueIndex) <0){
|
||||||
if (msgQueueReadTryLock(space->externId, queueIndex) < 0) {
|
NZG_ERROR("msgQueueReadTryLock",space->externId);
|
||||||
NZG_ERROR("msgQueueReadTryLock", space->externId);
|
goto ERROR;
|
||||||
goto ERROR;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (msgQueueReadLock(space->externId, queueIndex) < 0) {
|
|
||||||
NZG_ERROR("msgQueueReadLock", space->externId);
|
|
||||||
goto ERROR;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
// la lecture est possible
|
} else {
|
||||||
// on essaye donc de modifier la liste
|
if (msgQueueReadLock(space->externId,queueIndex) <0){
|
||||||
msgQueueProtLock(space->externId, queueIndex);
|
NZG_ERROR("msgQueueReadLock",space->externId);
|
||||||
msgQueueIdIntern(queueId, space->externId, queueIndex);
|
goto ERROR;
|
||||||
// ouvrir la file
|
|
||||||
queue = msgQueueOpen(queueId);
|
|
||||||
if (queue == NULL) {
|
|
||||||
NZG_ERROR("msgQueueOpen", queueId);
|
|
||||||
goto ERROR;
|
|
||||||
}
|
}
|
||||||
// recupérer l'id de l'ancien element...
|
}
|
||||||
msgQueueRem(queue, oldElemId);
|
// la lecture est possible
|
||||||
|
// on essaye donc de modifier la liste
|
||||||
|
msgQueueProtLock(space->externId,queueIndex);
|
||||||
|
msgQueueIdIntern(queueId,space->externId,queueIndex);
|
||||||
|
// ouvrir la file
|
||||||
|
queue = msgQueueOpen(queueId);
|
||||||
|
if (queue==NULL){
|
||||||
|
NZG_ERROR("msgQueueOpen",queueId);
|
||||||
|
goto ERROR;
|
||||||
|
}
|
||||||
|
// recupérer l'id de l'ancien element...
|
||||||
|
msgQueueRem(queue, oldElemId);
|
||||||
|
|
||||||
oldElem = msgQueueElemOpen(oldElemId);
|
oldElem = msgQueueElemOpen(oldElemId);
|
||||||
if (oldElem == NULL) {
|
if (oldElem == NULL){
|
||||||
NZG_ERROR("msgQueueElemOpen", oldElemId);
|
NZG_ERROR("msgQueueElemOpen",oldElemId);
|
||||||
goto ERROR;
|
goto ERROR;
|
||||||
}
|
}
|
||||||
/* on récupere la taille des buffer dans la pool du buffer */
|
/* on récupere la taille des buffer dans la pool du buffer */
|
||||||
poolDataTab = msgPoolDataTabOpen(space);
|
poolDataTab=msgPoolDataTabOpen(space);
|
||||||
// mapper le buffer dans l'espace mémoire du processus
|
// mapper le buffer dans l'espace mémoire du processus
|
||||||
resultAddr =
|
resultAddr=msgBufferMap(poolDataTab,oldElem->poolIndex,oldElem->bufferIndex);
|
||||||
msgBufferMap(poolDataTab, oldElem->poolIndex, oldElem->bufferIndex);
|
// attacher au buffer...
|
||||||
// attacher au buffer...
|
if (msgBufferAttachProc(poolDataTab,
|
||||||
if (msgBufferAttachProc(poolDataTab,
|
oldElem->poolIndex,
|
||||||
oldElem->poolIndex,
|
oldElem->bufferIndex,
|
||||||
oldElem->bufferIndex, resultAddr) < 0) {
|
resultAddr) <0){
|
||||||
NZG_ERROR("msgBufferAttachProc", oldElemId);
|
NZG_ERROR("msgBufferAttachProc",oldElemId);
|
||||||
goto ERROR;
|
goto ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
msgPoolDataTabClose(space, poolDataTab);
|
msgPoolDataTabClose(space,poolDataTab);
|
||||||
if (msgQueueElemClose(oldElem) < 0) {
|
if (msgQueueElemClose(oldElem) <0){
|
||||||
NZG_ERROR("msgQueueElemClose", oldElemId);
|
NZG_ERROR("msgQueueElemClose",oldElemId);
|
||||||
}
|
}
|
||||||
|
|
||||||
shm_unlink(oldElemId);
|
shm_unlink(oldElemId);
|
||||||
|
|
||||||
// fermer la file
|
// fermer la file
|
||||||
msgQueueClose(queue);
|
msgQueueClose(queue);
|
||||||
|
|
||||||
// on a fini de modifier la liste
|
// on a fini de modifier la liste
|
||||||
msgQueueProtUnlock(space->externId, queueIndex);
|
msgQueueProtUnlock(space->externId,queueIndex);
|
||||||
|
|
||||||
return resultAddr;
|
return resultAddr;
|
||||||
ERROR:
|
ERROR:
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,13 +1,13 @@
|
||||||
#ifndef _NZG_GLOBAL
|
#ifndef _NZG_GLOBAL
|
||||||
#define _NZG_GLOBAL 1
|
#define _NZG_GLOBAL 1
|
||||||
|
|
||||||
#include <unistd.h> /* POSIX et al */
|
#include <unistd.h> /* POSIX et al */
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <fcntl.h> /* pour O_RDWR */
|
#include <fcntl.h> /* pour O_RDWR */
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/mman.h> /* shm_open */
|
#include <sys/mman.h> /* shm_open */
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <semaphore.h>
|
#include <semaphore.h>
|
||||||
|
|
||||||
|
@ -25,10 +25,12 @@
|
||||||
#define SEM_FAILED ((sem_t *)0)
|
#define SEM_FAILED ((sem_t *)0)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#ifndef MAP_FAILED
|
#ifndef MAP_FAILED
|
||||||
#define MAP_FAILED ((void *)-1)
|
#define MAP_FAILED ((void *)-1)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#ifdef _NZG_REALFILEID
|
#ifdef _NZG_REALFILEID
|
||||||
#define DEFAULT_MSGSPACELISTID "/tmp/nzgSpaceList"
|
#define DEFAULT_MSGSPACELISTID "/tmp/nzgSpaceList"
|
||||||
#else
|
#else
|
||||||
|
|
|
@ -1,48 +0,0 @@
|
||||||
#ifndef _NZG_GLOBAL
|
|
||||||
#define _NZG_GLOBAL 1
|
|
||||||
|
|
||||||
#include <unistd.h> /* POSIX et al */
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <fcntl.h> /* pour O_RDWR */
|
|
||||||
#include <sys/types.h>
|
|
||||||
#include <sys/mman.h> /* shm_open */
|
|
||||||
#include <errno.h>
|
|
||||||
#include <semaphore.h>
|
|
||||||
|
|
||||||
#define PAGESIZE sysconf(_SC_PAGESIZE)
|
|
||||||
#define MSGSPACE_DEFAULT_MODE 0600
|
|
||||||
#define SEM_DEFAULT_MODE 0600
|
|
||||||
#define SHM_DEFAULT_MODE 0600
|
|
||||||
#define MSGSPACE_ID_LEN 32
|
|
||||||
#define ERR_UNHANDLED "Gérer mieu les erreurs"
|
|
||||||
|
|
||||||
#define ANYPOOL -1
|
|
||||||
#define SPECIFICPOOL 0
|
|
||||||
|
|
||||||
#ifndef SEM_FAILED
|
|
||||||
#define SEM_FAILED ((sem_t *)0)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
#ifndef MAP_FAILED
|
|
||||||
#define MAP_FAILED ((void *)-1)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef _NZG_REALFILEID
|
|
||||||
#define DEFAULT_MSGSPACELISTID "/tmp/nzgSpaceList"
|
|
||||||
#else
|
|
||||||
#define DEFAULT_MSGSPACELISTID "/nzgSpaceList"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef _NZG_REALFILEID
|
|
||||||
#define DEFAULT_MSGSPACELISTSEMID "/tmp/nzgSpaceListSem"
|
|
||||||
#else
|
|
||||||
#define DEFAULT_MSGSPACELISTSEMID "/nzgSpaceListSem"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define NZG_ERROR(func,str) fprintf(stderr,"*** %s: %s***\n%s in %s:%d\n",func,strerror(errno),str,__FILE__,__LINE__);
|
|
||||||
|
|
||||||
#endif
|
|
204
src/ids.c
204
src/ids.c
|
@ -1,150 +1,158 @@
|
||||||
#include "libnazgul.h"
|
#include "libnazgul.h"
|
||||||
#include "ids.h"
|
#include "ids.h"
|
||||||
|
|
||||||
int msgSpaceIdIntern(msgSpaceId dest, const msgSpaceId src)
|
int msgSpaceIdIntern(msgSpaceId dest,const msgSpaceId src ){
|
||||||
{
|
if (strlen(src)>MSGSPACE_ID_LEN){
|
||||||
if (strlen(src) > MSGSPACE_ID_LEN) {
|
return -1;
|
||||||
return -1;
|
}
|
||||||
}
|
/* sprintf(resNzgId,"/tmp/.nzg-%s",(char *)spaceId); */
|
||||||
/* sprintf(resNzgId,"/tmp/.nzg-%s",(char *)spaceId); */
|
|
||||||
#ifdef _NZG_REALFILEID
|
#ifdef _NZG_REALFILEID
|
||||||
sprintf(dest, "/tmp/nzgSpace%s", (char *)src);
|
sprintf(dest,"/tmp/nzgSpace%s",(char *)src);
|
||||||
#else
|
#else
|
||||||
sprintf(dest, "/nzgSpace%s", (char *)src);
|
sprintf(dest,"/nzgSpace%s",(char *)src);
|
||||||
#endif
|
#endif
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
int msgPoolDataTabSemIdIntern(
|
||||||
int msgPoolDataTabSemIdIntern(msgPoolSemId destSemId, const msgSpaceId externId)
|
msgPoolSemId destSemId,
|
||||||
{
|
const msgSpaceId externId){
|
||||||
if (strlen(externId) > MSGSPACE_ID_LEN * 4) {
|
if (strlen(externId)>MSGSPACE_ID_LEN*4){
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
/* sprintf(resNzgId,"/tmp/.nzg-%s",(char *)spaceId); */
|
/* sprintf(resNzgId,"/tmp/.nzg-%s",(char *)spaceId); */
|
||||||
#ifdef _NZG_REALFILEID
|
#ifdef _NZG_REALFILEID
|
||||||
sprintf(destSemId, "/tmp/nzgPoolDTSem-%s", (char *)externId);
|
sprintf(destSemId,"/tmp/nzgPoolDTSem-%s",(char *)externId);
|
||||||
#else
|
#else
|
||||||
sprintf(destSemId, "/nzgPoolDTSem-%s", (char *)externId);
|
sprintf(destSemId,"/nzgPoolDTSem-%s",(char *)externId);
|
||||||
#endif
|
#endif
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
int msgPoolSemIdIntern(
|
||||||
int msgPoolSemIdIntern(msgPoolSemId destSemId,
|
msgPoolSemId destSemId,
|
||||||
const msgSpaceId srcPoolId, int poolIdx)
|
const msgSpaceId srcPoolId,
|
||||||
{
|
int poolIdx){
|
||||||
if (strlen(srcPoolId) > MSGSPACE_ID_LEN * 4) {
|
if (strlen(srcPoolId)>MSGSPACE_ID_LEN*4){
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
/* sprintf(resNzgId,"/tmp/.nzg-%s",(char *)spaceId); */
|
/* sprintf(resNzgId,"/tmp/.nzg-%s",(char *)spaceId); */
|
||||||
#ifdef _NZG_REALFILEID
|
#ifdef _NZG_REALFILEID
|
||||||
sprintf(destSemId, "/tmp/nzgPoolSem-%s-%d", (char *)srcPoolId, poolIdx);
|
sprintf(destSemId,"/tmp/nzgPoolSem-%s-%d",(char *)srcPoolId,poolIdx);
|
||||||
#else
|
#else
|
||||||
sprintf(destSemId, "/nzgPoolSem-%s-%d", (char *)srcPoolId, poolIdx);
|
sprintf(destSemId,"/nzgPoolSem-%s-%d",(char *)srcPoolId,poolIdx);
|
||||||
#endif
|
#endif
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int msgPoolDataIdIntern(msgPoolDataTabId dest, const msgSpaceId src)
|
int msgPoolDataIdIntern(msgPoolDataTabId dest,const msgSpaceId src ){
|
||||||
{
|
if (strlen(src)>MSGSPACE_ID_LEN){
|
||||||
if (strlen(src) > MSGSPACE_ID_LEN) {
|
return -1;
|
||||||
return -1;
|
}
|
||||||
}
|
/* sprintf(resNzgId,"/tmp/.nzg-%s",(char *)spaceId); */
|
||||||
/* sprintf(resNzgId,"/tmp/.nzg-%s",(char *)spaceId); */
|
|
||||||
#ifdef _NZG_REALFILEID
|
#ifdef _NZG_REALFILEID
|
||||||
sprintf(dest, "/tmp/nzgPoolData-%s", (char *)src);
|
sprintf(dest,"/tmp/nzgPoolData-%s",(char *)src);
|
||||||
#else
|
#else
|
||||||
sprintf(dest, "/nzgPoolData-%s", (char *)src);
|
sprintf(dest,"/nzgPoolData-%s",(char *)src);
|
||||||
#endif
|
#endif
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int msgPoolIdIntern(msgPoolId dest, msgPoolId src, int num)
|
|
||||||
{
|
int msgPoolIdIntern(msgPoolId dest,msgPoolId src, int num){
|
||||||
if (strlen(src) > MSGSPACE_ID_LEN) {
|
if (strlen(src)>MSGSPACE_ID_LEN){
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
#ifdef _NZG_REALFILEID
|
#ifdef _NZG_REALFILEID
|
||||||
sprintf(dest, "/tmp/nzgPool-%s-%d", (char *)src, num);
|
sprintf(dest,"/tmp/nzgPool-%s-%d",(char *)src,num);
|
||||||
#else
|
#else
|
||||||
sprintf(dest, "/nzgPool-%s-%d", (char *)src, num);
|
sprintf(dest,"/nzgPool-%s-%d",(char *)src,num);
|
||||||
#endif
|
#endif
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int msgBufferInfoTabIdIntern(msgBufferInfoTabId dest, msgSpaceId src, int num)
|
int msgBufferInfoTabIdIntern(
|
||||||
{
|
msgBufferInfoTabId dest,
|
||||||
if (strlen(src) > MSGSPACE_ID_LEN) {
|
msgSpaceId src,
|
||||||
return -1;
|
int num){
|
||||||
}
|
if (strlen(src)>MSGSPACE_ID_LEN){
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
#ifdef _NZG_REALFILEID
|
#ifdef _NZG_REALFILEID
|
||||||
sprintf(dest, "/tmp/nzgBufferInfo-%s-%d", (char *)src, num);
|
sprintf(dest,"/tmp/nzgBufferInfo-%s-%d",(char *)src,num);
|
||||||
#else
|
#else
|
||||||
sprintf(dest, "/nzgBufferInfo-%s-%d", (char *)src, num);
|
sprintf(dest,"/nzgBufferInfo-%s-%d",(char *)src,num);
|
||||||
#endif
|
#endif
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int msgQueueProtSemIdIntern(msgQueueSemId dest,
|
int msgQueueProtSemIdIntern(
|
||||||
msgSpaceId externId, int queueIdx)
|
msgQueueSemId dest,
|
||||||
{
|
msgSpaceId externId,
|
||||||
if (strlen(externId) > MSGSPACE_ID_LEN) {
|
int queueIdx){
|
||||||
return -1;
|
if (strlen(externId)>MSGSPACE_ID_LEN){
|
||||||
}
|
return -1;
|
||||||
|
}
|
||||||
#ifdef _NZG_REALFILEID
|
#ifdef _NZG_REALFILEID
|
||||||
sprintf(dest, "/tmp/nzgQueueProtSem-%s-%d", (char *)externId, queueIdx);
|
sprintf(dest,"/tmp/nzgQueueProtSem-%s-%d",(char *)externId,queueIdx);
|
||||||
#else
|
#else
|
||||||
sprintf(dest, "/nzgQueueProtSem-%s-%d", (char *)externId, queueIdx);
|
sprintf(dest,"/nzgQueueProtSem-%s-%d",(char *)externId,queueIdx);
|
||||||
#endif
|
#endif
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int msgQueueReadSemIdIntern(msgQueueSemId dest,
|
int msgQueueReadSemIdIntern(
|
||||||
msgSpaceId externId, int queueIdx)
|
msgQueueSemId dest,
|
||||||
{
|
msgSpaceId externId,
|
||||||
if (strlen(externId) > MSGSPACE_ID_LEN) {
|
int queueIdx){
|
||||||
return -1;
|
if (strlen(externId)>MSGSPACE_ID_LEN){
|
||||||
}
|
return -1;
|
||||||
|
}
|
||||||
#ifdef _NZG_REALFILEID
|
#ifdef _NZG_REALFILEID
|
||||||
sprintf(dest, "/tmp/nzgQueueReadSem-%s-%d", (char *)externId, queueIdx);
|
sprintf(dest,"/tmp/nzgQueueReadSem-%s-%d",(char *)externId,queueIdx);
|
||||||
#else
|
#else
|
||||||
sprintf(dest, "/nzgQueueReadSem-%s-%d", (char *)externId, queueIdx);
|
sprintf(dest,"/nzgQueueReadSem-%s-%d",(char *)externId,queueIdx);
|
||||||
#endif
|
#endif
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int msgQueueIdIntern(msgQueueId dest, msgSpaceId externId, int queueIdx)
|
int msgQueueIdIntern(
|
||||||
{
|
msgQueueId dest,
|
||||||
if (strlen(externId) > MSGSPACE_ID_LEN) {
|
msgSpaceId externId,
|
||||||
return -1;
|
int queueIdx){
|
||||||
}
|
if (strlen(externId)>MSGSPACE_ID_LEN){
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
#ifdef _NZG_REALFILEID
|
#ifdef _NZG_REALFILEID
|
||||||
sprintf(dest, "/tmp/nzgQueue-%s-%d", (char *)externId, queueIdx);
|
sprintf(dest,"/tmp/nzgQueue-%s-%d",(char *)externId,queueIdx);
|
||||||
#else
|
#else
|
||||||
sprintf(dest, "/nzgQueue-%s-%d", (char *)externId, queueIdx);
|
sprintf(dest,"/nzgQueue-%s-%d",(char *)externId,queueIdx);
|
||||||
#endif
|
#endif
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int msgQueueElemIdIntern(msgQueueElemId dest, msgQueueId src, int counter)
|
int msgQueueElemIdIntern(
|
||||||
{
|
msgQueueElemId dest,
|
||||||
if (strlen(src) > MSGSPACE_ID_LEN) {
|
msgQueueId src,
|
||||||
return -1;
|
int counter){
|
||||||
}
|
if (strlen(src)>MSGSPACE_ID_LEN){
|
||||||
sprintf(dest, "%s-%d", (char *)src, counter);
|
return -1;
|
||||||
return 0;
|
}
|
||||||
|
sprintf(dest,"%s-%d",(char *)src,counter);
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int msgSpaceListElemIdIntern(msgSpaceListElemId elemListId, msgSpaceId externId)
|
int msgSpaceListElemIdIntern(msgSpaceListElemId elemListId,msgSpaceId externId){
|
||||||
{
|
if (strlen(externId)>MSGSPACE_ID_LEN){
|
||||||
if (strlen(externId) > MSGSPACE_ID_LEN) {
|
return -1;
|
||||||
return -1;
|
}
|
||||||
}
|
/* sprintf(resNzgId,"/tmp/.nzg-%s",(char *)spaceId); */
|
||||||
/* sprintf(resNzgId,"/tmp/.nzg-%s",(char *)spaceId); */
|
|
||||||
#ifdef _NZG_REALFILEID
|
#ifdef _NZG_REALFILEID
|
||||||
sprintf(elemListId, "/tmp/nzgSpaceListElem-%s", (char *)externId);
|
sprintf(elemListId,"/tmp/nzgSpaceListElem-%s",(char *)externId);
|
||||||
#else
|
#else
|
||||||
sprintf(elemListId, "/nzgSpaceListElem-%s", (char *)externId);
|
sprintf(elemListId,"/nzgSpaceListElem-%s",(char *)externId);
|
||||||
#endif
|
#endif
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
18
src/ids.h
18
src/ids.h
|
@ -2,13 +2,21 @@
|
||||||
#define _NZG_IDS 1
|
#define _NZG_IDS 1
|
||||||
#include "libnazgul.h"
|
#include "libnazgul.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* nzg_ids.c */
|
/* nzg_ids.c */
|
||||||
int msgSpaceIdIntern(msgSpaceId dest, const msgSpaceId src);
|
int msgSpaceIdIntern(msgSpaceId dest, const msgSpaceId src);
|
||||||
int msgPoolSemIdIntern(msgPoolSemId destSemId, const msgSpaceId srcPoolId,
|
int msgPoolSemIdIntern(msgPoolSemId destSemId, const msgSpaceId srcPoolId, int poolIdx);
|
||||||
int poolIdx);
|
|
||||||
int msgPoolDataIdIntern(msgPoolDataTabId dest, const msgSpaceId src);
|
int msgPoolDataIdIntern(msgPoolDataTabId dest, const msgSpaceId src);
|
||||||
int msgPoolIdIntern(msgPoolId dest, msgPoolId src, int num);
|
int msgPoolIdIntern(msgPoolId dest,msgPoolId src, int num);
|
||||||
int msgQueueSemIdIntern(msgQueueSemId dest, msgSpaceId externId, int queueIdx);
|
int msgQueueSemIdIntern(
|
||||||
int msgQueueIdIntern(msgQueueId dest, msgSpaceId externId, int queueIdx);
|
msgQueueSemId dest,
|
||||||
|
msgSpaceId externId,
|
||||||
|
int queueIdx);
|
||||||
|
int msgQueueIdIntern(
|
||||||
|
msgQueueId dest,
|
||||||
|
msgSpaceId externId,
|
||||||
|
int queueIdx);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
22
src/ids.h~
22
src/ids.h~
|
@ -1,22 +0,0 @@
|
||||||
#ifndef _NZG_IDS
|
|
||||||
#define _NZG_IDS 1
|
|
||||||
#include "libnazgul.h"
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* nzg_ids.c */
|
|
||||||
int msgSpaceIdIntern(msgSpaceId dest, const msgSpaceId src);
|
|
||||||
int msgPoolSemIdIntern(msgPoolSemId destSemId, const msgSpaceId srcPoolId, int poolIdx);
|
|
||||||
int msgPoolDataIdIntern(msgPoolDataTabId dest, const msgSpaceId src);
|
|
||||||
int msgPoolIdIntern(msgPoolId dest,msgPoolId src, int num);
|
|
||||||
int msgQueueSemIdIntern(
|
|
||||||
msgQueueSemId dest,
|
|
||||||
msgSpaceId externId,
|
|
||||||
int queueIdx);
|
|
||||||
int msgQueueIdIntern(
|
|
||||||
msgQueueId dest,
|
|
||||||
msgSpaceId externId,
|
|
||||||
int queueIdx);
|
|
||||||
|
|
||||||
#endif
|
|
96
src/iface.h
96
src/iface.h
|
@ -3,86 +3,88 @@
|
||||||
|
|
||||||
#include "global.h"
|
#include "global.h"
|
||||||
|
|
||||||
typedef enum { true = 1, false = 0 } bool;
|
typedef enum { true=1, false=0} bool;
|
||||||
|
|
||||||
typedef char msgSpaceId[MSGSPACE_ID_LEN];
|
typedef char msgSpaceId[MSGSPACE_ID_LEN];
|
||||||
|
|
||||||
typedef char msgSpaceListId[4 * MSGSPACE_ID_LEN];
|
typedef char msgSpaceListId[4*MSGSPACE_ID_LEN];
|
||||||
typedef char msgSpaceListSemId[4 * MSGSPACE_ID_LEN];
|
typedef char msgSpaceListSemId[4*MSGSPACE_ID_LEN];
|
||||||
typedef char msgSpaceListElemId[4 * MSGSPACE_ID_LEN];
|
typedef char msgSpaceListElemId[4*MSGSPACE_ID_LEN];
|
||||||
|
|
||||||
typedef char msgPoolDataTabId[4 * MSGSPACE_ID_LEN];
|
typedef char msgPoolDataTabId[4*MSGSPACE_ID_LEN];
|
||||||
typedef char msgPoolDataTabSemId[4 * MSGSPACE_ID_LEN];
|
typedef char msgPoolDataTabSemId[4*MSGSPACE_ID_LEN];
|
||||||
|
|
||||||
typedef char msgBufferInfoTabId[4 * MSGSPACE_ID_LEN];
|
typedef char msgBufferInfoTabId[4*MSGSPACE_ID_LEN];
|
||||||
|
|
||||||
typedef char msgPoolId[4 * MSGSPACE_ID_LEN];
|
typedef char msgPoolId[4*MSGSPACE_ID_LEN];
|
||||||
typedef char msgPoolSemId[4 * MSGSPACE_ID_LEN];
|
typedef char msgPoolSemId[4*MSGSPACE_ID_LEN];
|
||||||
|
|
||||||
typedef char msgQueueDataId[4 * MSGSPACE_ID_LEN];
|
typedef char msgQueueDataId[4*MSGSPACE_ID_LEN];
|
||||||
typedef char msgQueueId[4 * MSGSPACE_ID_LEN];
|
typedef char msgQueueId[4*MSGSPACE_ID_LEN];
|
||||||
typedef char msgQueueElemId[4 * MSGSPACE_ID_LEN];
|
typedef char msgQueueElemId[4*MSGSPACE_ID_LEN];
|
||||||
typedef char msgQueueSemId[4 * MSGSPACE_ID_LEN];
|
typedef char msgQueueSemId[4*MSGSPACE_ID_LEN];
|
||||||
|
|
||||||
/* pid[] */
|
/* pid[] */
|
||||||
/* liste des processus demandeurs */
|
/* liste des processus demandeurs */
|
||||||
typedef struct MsgPool {
|
typedef struct MsgPool {
|
||||||
int bufferSize;
|
int bufferSize;
|
||||||
int bufferNb;
|
int bufferNb;
|
||||||
} msgPool;
|
} msgPool;
|
||||||
|
|
||||||
typedef struct MsgBufferInfo {
|
typedef struct MsgBufferInfo {
|
||||||
pid_t ownerPid;
|
pid_t ownerPid;
|
||||||
void *addr;
|
void * addr;
|
||||||
} msgBufferInfo;
|
} msgBufferInfo;
|
||||||
|
|
||||||
typedef struct MsgPoolData {
|
typedef struct MsgPoolData {
|
||||||
msgPoolId poolId;
|
msgPoolId poolId;
|
||||||
msgBufferInfoTabId bufferInfoTabId;
|
msgBufferInfoTabId bufferInfoTabId;
|
||||||
int bufferNb;
|
int bufferNb;
|
||||||
int bufferSize;
|
int bufferSize;
|
||||||
int allocDispBuffer;
|
int allocDispBuffer;
|
||||||
} msgPoolData;
|
} msgPoolData;
|
||||||
|
|
||||||
/* TODO: queueId */
|
/* TODO: queueId */
|
||||||
|
|
||||||
|
|
||||||
typedef struct MsgSpace {
|
typedef struct MsgSpace {
|
||||||
msgSpaceId id;
|
msgSpaceId id;
|
||||||
msgSpaceId externId;
|
msgSpaceId externId;
|
||||||
int poolNb;
|
int poolNb;
|
||||||
int queueNb;
|
int queueNb;
|
||||||
int pid;
|
int pid;
|
||||||
msgPoolDataTabId poolDataTabId;
|
msgPoolDataTabId poolDataTabId;
|
||||||
msgPoolDataTabSemId poolDataTabSemId;
|
msgPoolDataTabSemId poolDataTabSemId;
|
||||||
} msgSpace;
|
} msgSpace;
|
||||||
|
|
||||||
typedef struct MsgSpaceListElem {
|
|
||||||
msgSpaceListElemId id;
|
|
||||||
|
|
||||||
msgSpaceId spaceId;
|
typedef struct MsgSpaceListElem {
|
||||||
msgSpaceListElemId next;
|
msgSpaceListElemId id;
|
||||||
|
|
||||||
|
msgSpaceId spaceId;
|
||||||
|
msgSpaceListElemId next;
|
||||||
} msgSpaceListElem;
|
} msgSpaceListElem;
|
||||||
|
|
||||||
typedef struct MsgSpaceList {
|
typedef struct MsgSpaceList {
|
||||||
msgSpaceListId id;
|
msgSpaceListId id;
|
||||||
|
|
||||||
int elemCounter;
|
int elemCounter;
|
||||||
msgSpaceListElemId headId;
|
msgSpaceListElemId headId;
|
||||||
msgSpaceListElemId tailId;
|
msgSpaceListElemId tailId;
|
||||||
} msgSpaceList;
|
} msgSpaceList;
|
||||||
|
|
||||||
typedef struct MsgQueueElem {
|
typedef struct MsgQueueElem {
|
||||||
msgQueueElemId id;
|
msgQueueElemId id;
|
||||||
int poolIndex;
|
int poolIndex;
|
||||||
int bufferIndex;
|
int bufferIndex;
|
||||||
msgQueueElemId next;
|
msgQueueElemId next;
|
||||||
} msgQueueElem;
|
} msgQueueElem;
|
||||||
|
|
||||||
typedef struct MsgQueue {
|
typedef struct MsgQueue {
|
||||||
msgQueueId id;
|
msgQueueId id;
|
||||||
int elemCounter;
|
int elemCounter;
|
||||||
msgQueueElemId headId;
|
msgQueueElemId headId;
|
||||||
msgQueueElemId tailId;
|
msgQueueElemId tailId;
|
||||||
} msgQueue;
|
} msgQueue;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
91
src/iface.h~
91
src/iface.h~
|
@ -1,91 +0,0 @@
|
||||||
#ifndef _NZG_IFACE
|
|
||||||
#define _NZG_IFACE 1
|
|
||||||
|
|
||||||
#include "global.h"
|
|
||||||
|
|
||||||
typedef enum { true=1, false=0} bool;
|
|
||||||
|
|
||||||
typedef char msgSpaceId[MSGSPACE_ID_LEN];
|
|
||||||
|
|
||||||
typedef char msgSpaceListId[4*MSGSPACE_ID_LEN];
|
|
||||||
typedef char msgSpaceListSemId[4*MSGSPACE_ID_LEN];
|
|
||||||
typedef char msgSpaceListElemId[4*MSGSPACE_ID_LEN];
|
|
||||||
|
|
||||||
typedef char msgPoolDataTabId[4*MSGSPACE_ID_LEN];
|
|
||||||
typedef char msgPoolDataTabSemId[4*MSGSPACE_ID_LEN];
|
|
||||||
|
|
||||||
typedef char msgBufferInfoTabId[4*MSGSPACE_ID_LEN];
|
|
||||||
|
|
||||||
typedef char msgPoolId[4*MSGSPACE_ID_LEN];
|
|
||||||
typedef char msgPoolSemId[4*MSGSPACE_ID_LEN];
|
|
||||||
|
|
||||||
typedef char msgQueueDataId[4*MSGSPACE_ID_LEN];
|
|
||||||
typedef char msgQueueId[4*MSGSPACE_ID_LEN];
|
|
||||||
typedef char msgQueueElemId[4*MSGSPACE_ID_LEN];
|
|
||||||
typedef char msgQueueSemId[4*MSGSPACE_ID_LEN];
|
|
||||||
|
|
||||||
/* pid[] */
|
|
||||||
/* liste des processus demandeurs */
|
|
||||||
typedef struct MsgPool {
|
|
||||||
int bufferSize;
|
|
||||||
int bufferNb;
|
|
||||||
} msgPool;
|
|
||||||
|
|
||||||
typedef struct MsgBufferInfo {
|
|
||||||
pid_t ownerPid;
|
|
||||||
void * addr;
|
|
||||||
} msgBufferInfo;
|
|
||||||
|
|
||||||
typedef struct MsgPoolData {
|
|
||||||
msgPoolId poolId;
|
|
||||||
msgBufferInfoTabId bufferInfoTabId;
|
|
||||||
int bufferNb;
|
|
||||||
int bufferSize;
|
|
||||||
int allocDispBuffer;
|
|
||||||
} msgPoolData;
|
|
||||||
|
|
||||||
/* TODO: queueId */
|
|
||||||
|
|
||||||
|
|
||||||
typedef struct MsgSpace {
|
|
||||||
msgSpaceId id;
|
|
||||||
msgSpaceId externId;
|
|
||||||
int poolNb;
|
|
||||||
int queueNb;
|
|
||||||
int pid;
|
|
||||||
msgPoolDataTabId poolDataTabId;
|
|
||||||
msgPoolDataTabSemId poolDataTabSemId;
|
|
||||||
} msgSpace;
|
|
||||||
|
|
||||||
|
|
||||||
typedef struct MsgSpaceListElem {
|
|
||||||
msgSpaceListElemId id;
|
|
||||||
|
|
||||||
msgSpaceId spaceId;
|
|
||||||
msgSpaceListElemId next;
|
|
||||||
} msgSpaceListElem;
|
|
||||||
|
|
||||||
typedef struct MsgSpaceList {
|
|
||||||
msgSpaceListId id;
|
|
||||||
|
|
||||||
int elemCounter;
|
|
||||||
msgSpaceListElemId headId;
|
|
||||||
msgSpaceListElemId tailId;
|
|
||||||
} msgSpaceList;
|
|
||||||
|
|
||||||
typedef struct MsgQueueElem {
|
|
||||||
msgQueueElemId id;
|
|
||||||
int poolIndex;
|
|
||||||
int bufferIndex;
|
|
||||||
msgQueueElemId next;
|
|
||||||
} msgQueueElem;
|
|
||||||
|
|
||||||
typedef struct MsgQueue {
|
|
||||||
msgQueueId id;
|
|
||||||
int elemCounter;
|
|
||||||
msgQueueElemId headId;
|
|
||||||
msgQueueElemId tailId;
|
|
||||||
} msgQueue;
|
|
||||||
|
|
||||||
#endif
|
|
||||||
/* */
|
|
|
@ -1,8 +0,0 @@
|
||||||
#ifndef _LIBNAZGUL
|
|
||||||
#define _LIBNAZGUL 1
|
|
||||||
|
|
||||||
#include "global.h"
|
|
||||||
#include "iface.h"
|
|
||||||
#include "proto.h"
|
|
||||||
|
|
||||||
#endif
|
|
|
@ -1,52 +1,50 @@
|
||||||
#include "libnazgul.h"
|
#include "libnazgul.h"
|
||||||
#include "ids.h"
|
#include "ids.h"
|
||||||
|
|
||||||
int msgPoolCreate(msgSpaceId externId, int poolIdx, int buffNb, int buffSize)
|
int msgPoolCreate(
|
||||||
{
|
msgSpaceId externId,
|
||||||
|
int poolIdx,
|
||||||
|
int buffNb,
|
||||||
|
int buffSize
|
||||||
|
) {
|
||||||
|
|
||||||
int poolFd;
|
int poolFd;
|
||||||
sem_t *ressourceSemFd;
|
sem_t * ressourceSemFd;
|
||||||
msgPoolId poolId;
|
msgPoolId poolId;
|
||||||
msgPoolSemId poolRessourceSemId;
|
msgPoolSemId poolRessourceSemId;
|
||||||
|
|
||||||
/* creation des buffers DEBUT */
|
/* creation des buffers DEBUT */
|
||||||
if (msgPoolIdIntern(poolId, externId, poolIdx) == -1) {
|
if (msgPoolIdIntern(poolId,externId,poolIdx) == -1){
|
||||||
fprintf(stderr, "msgPoolId creation failed for id %s\n",
|
fprintf( stderr, "msgPoolId creation failed for id %s\n", (char*)poolId );
|
||||||
(char *)poolId);
|
return -1;
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
poolFd =
|
poolFd=shm_open(poolId,O_RDWR|O_CREAT|O_EXCL|O_TRUNC,MSGSPACE_DEFAULT_MODE);
|
||||||
shm_open(poolId, O_RDWR | O_CREAT | O_EXCL | O_TRUNC,
|
if (poolFd == -1 ) {
|
||||||
MSGSPACE_DEFAULT_MODE);
|
fprintf( stderr, "msgPool : %s creation failed: %s\n",poolId,
|
||||||
if (poolFd == -1) {
|
strerror( errno ) );
|
||||||
fprintf(stderr, "msgPool : %s creation failed: %s\n", poolId,
|
return -1;
|
||||||
strerror(errno));
|
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
if (ftruncate(poolFd, (buffSize * buffNb)) == -1) {
|
if (ftruncate(poolFd, (buffSize*buffNb)) == -1){
|
||||||
fprintf(stderr, "msgPool resizing failed: %s\n",
|
fprintf( stderr, "msgPool resizing failed: %s\n",
|
||||||
strerror(errno));
|
strerror( errno ) );
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
/* creation des buffers FIN */
|
/* creation des buffers FIN */
|
||||||
|
|
||||||
if (msgPoolSemIdIntern(poolRessourceSemId, externId, poolIdx) == -1) {
|
if (msgPoolSemIdIntern(poolRessourceSemId,externId,poolIdx) == -1){
|
||||||
fprintf(stderr, "msgPoolId creation failed for id %s\n",
|
fprintf( stderr, "msgPoolId creation failed for id %s\n",
|
||||||
(char *)poolRessourceSemId);
|
(char*)poolRessourceSemId );
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// on met un semaphore sur le pool
|
// on met un semaphore sur le pool
|
||||||
ressourceSemFd =
|
ressourceSemFd = sem_open(poolRessourceSemId, O_CREAT|O_EXCL,SEM_DEFAULT_MODE, buffNb);
|
||||||
sem_open(poolRessourceSemId, O_CREAT | O_EXCL, SEM_DEFAULT_MODE,
|
if (ressourceSemFd == SEM_FAILED){
|
||||||
buffNb);
|
NZG_ERROR("sem_open : creation de la ressource",poolRessourceSemId);
|
||||||
if (ressourceSemFd == SEM_FAILED) {
|
goto ERROR;
|
||||||
NZG_ERROR("sem_open : creation de la ressource",
|
} else {
|
||||||
poolRessourceSemId);
|
printf("[ Created %s with %d ressources ]\n",poolRessourceSemId,buffNb);
|
||||||
goto ERROR;
|
}
|
||||||
} else {
|
|
||||||
printf("[ Created %s with %d ressources ]\n",
|
|
||||||
poolRessourceSemId, buffNb);
|
|
||||||
}
|
|
||||||
|
|
||||||
//TODO: verrifier les erreurs sur l'ouverture de la sem
|
//TODO: verrifier les erreurs sur l'ouverture de la sem
|
||||||
|
|
||||||
|
@ -57,6 +55,7 @@ int msgPoolCreate(msgSpaceId externId, int poolIdx, int buffNb, int buffSize)
|
||||||
close(poolFd);
|
close(poolFd);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
ERROR:
|
ERROR:
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,14 +1,13 @@
|
||||||
#include "libnazgul.h"
|
#include "libnazgul.h"
|
||||||
|
|
||||||
int msgPoolDataTabClose(msgSpace * space, void *addr)
|
int msgPoolDataTabClose(msgSpace * space,void * addr){
|
||||||
{
|
/* unmapper le msgPoolDataTab */
|
||||||
/* unmapper le msgPoolDataTab */
|
|
||||||
|
|
||||||
if (munmap(addr, (space->poolNb) * sizeof(msgPoolData)) < 0) {
|
if (munmap(addr,(space->poolNb) * sizeof( msgPoolData )) < 0){
|
||||||
NZG_ERROR("unmap", space->poolDataTabId);
|
NZG_ERROR("unmap",space->poolDataTabId);
|
||||||
goto ERROR;
|
goto ERROR;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
ERROR:
|
ERROR:
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,39 +1,42 @@
|
||||||
#include "libnazgul.h"
|
#include "libnazgul.h"
|
||||||
#include "ids.h"
|
#include "ids.h"
|
||||||
|
|
||||||
void *msgPoolDataTabCreate(msgSpace * space)
|
void * msgPoolDataTabCreate(msgSpace * space){
|
||||||
{
|
int poolDataFd; // shm file descriptor
|
||||||
int poolDataFd; // shm file descriptor
|
msgPoolData * poolDataTabAddr;
|
||||||
msgPoolData *poolDataTabAddr;
|
poolDataFd=shm_open(
|
||||||
poolDataFd = shm_open(space->poolDataTabId,
|
space->poolDataTabId,
|
||||||
O_RDWR | O_CREAT | O_EXCL | O_TRUNC,
|
O_RDWR|O_CREAT|O_EXCL|O_TRUNC,
|
||||||
MSGSPACE_DEFAULT_MODE);
|
MSGSPACE_DEFAULT_MODE
|
||||||
if (poolDataFd == -1) {
|
);
|
||||||
NZG_ERROR("shm_open :create", space->poolDataTabId);
|
if (poolDataFd == -1 ) {
|
||||||
goto ERROR;
|
NZG_ERROR("shm_open :create",space->poolDataTabId);
|
||||||
}
|
goto ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
/* allocation de la bonne zone mémoire pour le poolData */
|
/* allocation de la bonne zone mémoire pour le poolData */
|
||||||
if (ftruncate(poolDataFd, (space->poolNb) * sizeof(msgPoolData)) == -1) {
|
if (ftruncate(poolDataFd, (space->poolNb)*sizeof(msgPoolData)) == -1){
|
||||||
NZG_ERROR("ftruncate", space->poolDataTabId);
|
NZG_ERROR("ftruncate",space->poolDataTabId);
|
||||||
goto ERROR;
|
goto ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
close(poolDataFd);
|
close(poolDataFd);
|
||||||
poolDataTabAddr = msgPoolDataTabOpen(space);
|
poolDataTabAddr = msgPoolDataTabOpen(space);
|
||||||
if (poolDataTabAddr == NULL) {
|
if (poolDataTabAddr == NULL){
|
||||||
NZG_ERROR("msgPoolDataTabOpen : create", space->poolDataTabId);
|
NZG_ERROR("msgPoolDataTabOpen : create",space->poolDataTabId);
|
||||||
goto ERROR;
|
goto ERROR;
|
||||||
}
|
}
|
||||||
/*mmap( 0, sizeof( *mSAddr ),
|
/*mmap( 0, sizeof( *mSAddr ),
|
||||||
PROT_READ | PROT_WRITE,
|
PROT_READ | PROT_WRITE,
|
||||||
MAP_SHARED, mSFd, 0 );
|
MAP_SHARED, mSFd, 0 );
|
||||||
if( poolDataAddr == MAP_FAILED ) {
|
if( poolDataAddr == MAP_FAILED ) {
|
||||||
NZG_ERROR("mmap",poolDataTabId);
|
NZG_ERROR("mmap",poolDataTabId);
|
||||||
goto ERROR;
|
goto ERROR;
|
||||||
} */
|
}*/
|
||||||
|
|
||||||
return poolDataTabAddr;
|
return poolDataTabAddr;
|
||||||
ERROR:
|
ERROR:
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -3,35 +3,34 @@
|
||||||
|
|
||||||
#define DEBUG 0
|
#define DEBUG 0
|
||||||
|
|
||||||
int msgPoolDataTabLock(msgSpace * space)
|
int msgPoolDataTabLock(msgSpace * space){
|
||||||
{
|
int semval;
|
||||||
int semval;
|
sem_t * poolDataTabSemFd;
|
||||||
sem_t *poolDataTabSemFd;
|
semval=0;
|
||||||
semval = 0;
|
if (DEBUG) {printf("Locking %s\n",space->poolDataTabSemId);}
|
||||||
if (DEBUG) {
|
|
||||||
printf("Locking %s\n", space->poolDataTabSemId);
|
|
||||||
}
|
|
||||||
|
|
||||||
poolDataTabSemFd = sem_open(space->poolDataTabSemId, O_CREAT,
|
poolDataTabSemFd=sem_open(
|
||||||
SEM_DEFAULT_MODE, 1);
|
space->poolDataTabSemId
|
||||||
if (poolDataTabSemFd == SEM_FAILED) {
|
,O_CREAT,
|
||||||
NZG_ERROR("sem_open", space->poolDataTabSemId);
|
SEM_DEFAULT_MODE,
|
||||||
goto ERROR;
|
1);
|
||||||
}
|
if(poolDataTabSemFd==SEM_FAILED){
|
||||||
|
NZG_ERROR("sem_open",space->poolDataTabSemId);
|
||||||
|
goto ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
if (sem_wait(poolDataTabSemFd) == -1) {
|
if(sem_wait(poolDataTabSemFd)==-1){
|
||||||
NZG_ERROR("sem_wait", space->poolDataTabSemId);
|
NZG_ERROR("sem_wait",space->poolDataTabSemId);
|
||||||
goto ERROR;
|
goto ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
sem_getvalue(poolDataTabSemFd, &semval);
|
sem_getvalue(poolDataTabSemFd,&semval);
|
||||||
if (DEBUG) {
|
if (DEBUG) { printf("(AfternValue:%d)\n",semval);}
|
||||||
printf("(AfternValue:%d)\n", semval);
|
|
||||||
}
|
|
||||||
|
|
||||||
sem_close(poolDataTabSemFd);
|
sem_close(poolDataTabSemFd);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
ERROR:
|
ERROR:
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,30 +1,31 @@
|
||||||
#include "libnazgul.h"
|
#include "libnazgul.h"
|
||||||
#include "ids.h"
|
#include "ids.h"
|
||||||
|
|
||||||
void *msgPoolDataTabOpen(msgSpace * space)
|
void * msgPoolDataTabOpen(msgSpace * space){
|
||||||
{
|
int poolDataTabFd;
|
||||||
int poolDataTabFd;
|
void * poolDataTabAddr;
|
||||||
void *poolDataTabAddr;
|
|
||||||
|
|
||||||
poolDataTabFd = shm_open(space->poolDataTabId,
|
poolDataTabFd=shm_open(space->poolDataTabId,
|
||||||
O_RDWR, MSGSPACE_DEFAULT_MODE);
|
O_RDWR,
|
||||||
if (poolDataTabFd == -1) {
|
MSGSPACE_DEFAULT_MODE);
|
||||||
NZG_ERROR("shm_open", space->poolDataTabId);
|
if (poolDataTabFd == -1 ) {
|
||||||
goto ERROR;
|
NZG_ERROR("shm_open",space->poolDataTabId);
|
||||||
}
|
goto ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
poolDataTabAddr = mmap(NULL, (space->poolNb) * sizeof(msgPoolData),
|
|
||||||
PROT_READ | PROT_WRITE,
|
|
||||||
MAP_SHARED, poolDataTabFd, 0);
|
|
||||||
|
|
||||||
if (poolDataTabAddr == MAP_FAILED) {
|
poolDataTabAddr = mmap( NULL, (space->poolNb) * sizeof( msgPoolData ),
|
||||||
NZG_ERROR("mmap", space->poolDataTabId);
|
PROT_READ | PROT_WRITE,
|
||||||
goto ERROR;
|
MAP_SHARED, poolDataTabFd, 0 );
|
||||||
}
|
|
||||||
|
|
||||||
close(poolDataTabFd);
|
if( poolDataTabAddr == MAP_FAILED) {
|
||||||
|
NZG_ERROR("mmap",space->poolDataTabId);
|
||||||
|
goto ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
return poolDataTabAddr;
|
close(poolDataTabFd);
|
||||||
ERROR:
|
|
||||||
return NULL;
|
return poolDataTabAddr;
|
||||||
|
ERROR:
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,34 +3,33 @@
|
||||||
|
|
||||||
#define DEBUG 0
|
#define DEBUG 0
|
||||||
|
|
||||||
int msgPoolDataTabUnlock(msgSpace * space)
|
int msgPoolDataTabUnlock(msgSpace * space){
|
||||||
{
|
int semval;
|
||||||
int semval;
|
sem_t * poolDataTabSemFd;
|
||||||
sem_t *poolDataTabSemFd;
|
if (DEBUG) { printf("Unlocking %s\n",space->poolDataTabSemId); }
|
||||||
if (DEBUG) {
|
poolDataTabSemFd=sem_open(
|
||||||
printf("Unlocking %s\n", space->poolDataTabSemId);
|
space->poolDataTabSemId
|
||||||
}
|
,O_CREAT,
|
||||||
poolDataTabSemFd = sem_open(space->poolDataTabSemId, O_CREAT,
|
SEM_DEFAULT_MODE,
|
||||||
SEM_DEFAULT_MODE, 1);
|
1);
|
||||||
if (poolDataTabSemFd == SEM_FAILED) {
|
if(poolDataTabSemFd==SEM_FAILED){
|
||||||
NZG_ERROR("sem_open", space->poolDataTabSemId);
|
NZG_ERROR("sem_open",space->poolDataTabSemId);
|
||||||
goto ERROR;
|
goto ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sem_post(poolDataTabSemFd) == -1) {
|
if(sem_post(poolDataTabSemFd)==-1){
|
||||||
NZG_ERROR("sem_post", space->poolDataTabSemId);
|
NZG_ERROR("sem_post",space->poolDataTabSemId);
|
||||||
goto ERROR;
|
goto ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
semval=0;
|
||||||
|
sem_getvalue(poolDataTabSemFd,&semval);
|
||||||
|
if (DEBUG) { printf("(AfternValue:%d)\n",semval); }
|
||||||
|
|
||||||
semval = 0;
|
sem_close(poolDataTabSemFd);
|
||||||
sem_getvalue(poolDataTabSemFd, &semval);
|
|
||||||
if (DEBUG) {
|
|
||||||
printf("(AfternValue:%d)\n", semval);
|
|
||||||
}
|
|
||||||
|
|
||||||
sem_close(poolDataTabSemFd);
|
return 0;
|
||||||
|
ERROR:
|
||||||
return 0;
|
return -1;
|
||||||
ERROR:
|
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,49 +1,50 @@
|
||||||
#include "libnazgul.h"
|
#include "libnazgul.h"
|
||||||
#include "ids.h"
|
#include "ids.h"
|
||||||
|
|
||||||
int msgPoolDelete(msgSpaceId spaceId, int poolIdx)
|
int msgPoolDelete(
|
||||||
{
|
msgSpaceId spaceId,
|
||||||
|
int poolIdx
|
||||||
|
) {
|
||||||
|
|
||||||
msgPoolId poolId;
|
msgPoolId poolId;
|
||||||
msgBufferInfoTabId bufferInfoTabId;
|
msgBufferInfoTabId bufferInfoTabId;
|
||||||
msgPoolSemId poolRessourceSemId;
|
msgPoolSemId poolRessourceSemId;
|
||||||
|
|
||||||
|
|
||||||
/* suppression des infos sur buffers DEBUT */
|
/* suppression des infos sur buffers DEBUT */
|
||||||
if (msgBufferInfoTabIdIntern(bufferInfoTabId, spaceId, poolIdx) == -1) {
|
if (msgBufferInfoTabIdIntern(bufferInfoTabId,spaceId,poolIdx) == -1){
|
||||||
fprintf(stderr, "msgPoolId creation failed for id %s\n",
|
fprintf( stderr, "msgPoolId creation failed for id %s\n", (char*)poolId );
|
||||||
(char *)poolId);
|
return -1;
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (shm_unlink(bufferInfoTabId) < 0) {
|
if (shm_unlink(bufferInfoTabId) <0 ) {
|
||||||
fprintf(stderr, "msgInfoTab : %s deletion failed: %s\n",
|
fprintf( stderr, "msgInfoTab : %s deletion failed: %s\n",bufferInfoTabId,
|
||||||
bufferInfoTabId, strerror(errno));
|
strerror( errno ) );
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
/* suppression des infos sur buffers FIN */
|
/* suppression des infos sur buffers FIN */
|
||||||
|
|
||||||
/* suppression des buffers DEBUT */
|
/* suppression des buffers DEBUT */
|
||||||
if (msgPoolIdIntern(poolId, spaceId, poolIdx) == -1) {
|
if (msgPoolIdIntern(poolId,spaceId,poolIdx) == -1){
|
||||||
fprintf(stderr, "msgPoolId creation failed for id %s\n",
|
fprintf( stderr, "msgPoolId creation failed for id %s\n", (char*)poolId );
|
||||||
(char *)poolId);
|
return -1;
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
if (shm_unlink(poolId) < 0) {
|
if (shm_unlink(poolId) <0 ) {
|
||||||
fprintf(stderr, "msgPool : %s deletion failed: %s\n", poolId,
|
fprintf( stderr, "msgPool : %s deletion failed: %s\n",poolId,
|
||||||
strerror(errno));
|
strerror( errno ) );
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
/* suppression des buffers FIN */
|
/* suppression des buffers FIN */
|
||||||
|
|
||||||
/* suppression de la sémaphore */
|
/* suppression de la sémaphore */
|
||||||
if (msgPoolSemIdIntern(poolRessourceSemId, spaceId, poolIdx) == -1) {
|
if (msgPoolSemIdIntern(poolRessourceSemId,spaceId,poolIdx) == -1){
|
||||||
fprintf(stderr, "msgPoolId creation failed for id %s\n",
|
fprintf( stderr, "msgPoolId creation failed for id %s\n",
|
||||||
(char *)poolRessourceSemId);
|
(char*)poolRessourceSemId );
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
// on met un semaphore sur le pool
|
// on met un semaphore sur le pool
|
||||||
sem_unlink(poolRessourceSemId);
|
sem_unlink(poolRessourceSemId);
|
||||||
//TODO: verrifier les erreurs sur l'ouverture de la sem
|
//TODO: verrifier les erreurs sur l'ouverture de la sem
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
76
src/proto.h
76
src/proto.h
|
@ -2,77 +2,66 @@
|
||||||
#define _NZG_PROTO 1
|
#define _NZG_PROTO 1
|
||||||
|
|
||||||
/* allocate.c */
|
/* allocate.c */
|
||||||
void *msgAllocate(msgSpace * space, int pool, int taille, int option);
|
void *msgAllocate(msgSpace *space, int pool, int taille, int option);
|
||||||
/* bufferAttachProc.c */
|
/* bufferAttachProc.c */
|
||||||
int msgBufferAttachProc(msgPoolData * poolDataTabAddr, int poolIndex,
|
int msgBufferAttachProc(msgPoolData *poolDataTabAddr, int poolIndex, int bufferIndex, void *addr);
|
||||||
int bufferIndex, void *addr);
|
|
||||||
/* buffer.c */
|
/* buffer.c */
|
||||||
int msgBufferGetAttachedProcIndex(msgPoolData * poolDataTabAddr, int poolIndex,
|
int msgBufferGetAttachedProcIndex(msgPoolData *poolDataTabAddr, int poolIndex, void *addr);
|
||||||
void *addr);
|
|
||||||
/* bufferDetachProc.c */
|
/* bufferDetachProc.c */
|
||||||
int msgBufferDetachProc(msgPoolData * poolDataTabAddr, int poolIndex,
|
int msgBufferDetachProc(msgPoolData *poolDataTabAddr, int poolIndex, int bufferIndex, void *addr);
|
||||||
int bufferIndex, void *addr);
|
|
||||||
/* bufferGetFreeIndex.c */
|
/* bufferGetFreeIndex.c */
|
||||||
int msgBufferGetFreeIndex(msgPoolData * poolDataTabAddr, int poolIndex);
|
int msgBufferGetFreeIndex(msgPoolData *poolDataTabAddr, int poolIndex);
|
||||||
/* bufferGetProcAttach.c */
|
/* bufferGetProcAttach.c */
|
||||||
int msgBufferGetProcAttach(msgPoolData * poolDataTabAddr, int poolNb,
|
int msgBufferGetProcAttach(msgPoolData *poolDataTabAddr, int poolNb, int *poolIndex, int *bufferIndex, void *addr);
|
||||||
int *poolIndex, int *bufferIndex, void *addr);
|
|
||||||
/* bufferInfoTabCreate.c */
|
/* bufferInfoTabCreate.c */
|
||||||
int msgBufferInfoTabCreate(msgSpaceId externId, msgPoolData * poolDataTabAddr,
|
int msgBufferInfoTabCreate(msgSpaceId externId, msgPoolData *poolDataTabAddr, int poolIdx, int bufferNb);
|
||||||
int poolIdx, int bufferNb);
|
|
||||||
/* bufferInfoTabInit.c */
|
/* bufferInfoTabInit.c */
|
||||||
int msgBufferInfoTabInit(msgPoolData * poolDataTabAddr, int poolIndex);
|
int msgBufferInfoTabInit(msgPoolData *poolDataTabAddr, int poolIndex);
|
||||||
/* bufferMap.c */
|
/* bufferMap.c */
|
||||||
void *msgBufferMap(msgPoolData * poolDataTab, int poolIndex, int bufferIndex);
|
void *msgBufferMap(msgPoolData *poolDataTab, int poolIndex, int bufferIndex);
|
||||||
/* free.c */
|
/* free.c */
|
||||||
int msgFree(msgSpace * space, void *addr);
|
int msgFree(msgSpace *space, void *addr);
|
||||||
/* get.c */
|
/* get.c */
|
||||||
void *msgGet(msgSpace * space, int queueIndex, int option);
|
void *msgGet(msgSpace *space, int queueIndex, int option);
|
||||||
/* ids.c */
|
/* ids.c */
|
||||||
int msgSpaceIdIntern(msgSpaceId dest, const msgSpaceId src);
|
int msgSpaceIdIntern(msgSpaceId dest, const msgSpaceId src);
|
||||||
int msgPoolDataTabSemIdIntern(msgPoolSemId destSemId,
|
int msgPoolDataTabSemIdIntern(msgPoolSemId destSemId, const msgSpaceId externId);
|
||||||
const msgSpaceId externId);
|
int msgPoolSemIdIntern(msgPoolSemId destSemId, const msgSpaceId srcPoolId, int poolIdx);
|
||||||
int msgPoolSemIdIntern(msgPoolSemId destSemId, const msgSpaceId srcPoolId,
|
|
||||||
int poolIdx);
|
|
||||||
int msgPoolDataIdIntern(msgPoolDataTabId dest, const msgSpaceId src);
|
int msgPoolDataIdIntern(msgPoolDataTabId dest, const msgSpaceId src);
|
||||||
int msgPoolIdIntern(msgPoolId dest, msgPoolId src, int num);
|
int msgPoolIdIntern(msgPoolId dest, msgPoolId src, int num);
|
||||||
int msgBufferInfoTabIdIntern(msgBufferInfoTabId dest, msgSpaceId src, int num);
|
int msgBufferInfoTabIdIntern(msgBufferInfoTabId dest, msgSpaceId src, int num);
|
||||||
int msgQueueProtSemIdIntern(msgQueueSemId dest, msgSpaceId externId,
|
int msgQueueProtSemIdIntern(msgQueueSemId dest, msgSpaceId externId, int queueIdx);
|
||||||
int queueIdx);
|
int msgQueueReadSemIdIntern(msgQueueSemId dest, msgSpaceId externId, int queueIdx);
|
||||||
int msgQueueReadSemIdIntern(msgQueueSemId dest, msgSpaceId externId,
|
|
||||||
int queueIdx);
|
|
||||||
int msgQueueIdIntern(msgQueueId dest, msgSpaceId externId, int queueIdx);
|
int msgQueueIdIntern(msgQueueId dest, msgSpaceId externId, int queueIdx);
|
||||||
int msgQueueElemIdIntern(msgQueueElemId dest, msgQueueId src, int counter);
|
int msgQueueElemIdIntern(msgQueueElemId dest, msgQueueId src, int counter);
|
||||||
int msgSpaceListElemIdIntern(msgSpaceListElemId elemListId,
|
int msgSpaceListElemIdIntern(msgSpaceListElemId elemListId, msgSpaceId externId);
|
||||||
msgSpaceId externId);
|
|
||||||
/* list.c */
|
/* list.c */
|
||||||
/* poolCreate.c */
|
/* poolCreate.c */
|
||||||
int msgPoolCreate(msgSpaceId externId, int poolIdx, int buffNb, int buffSize);
|
int msgPoolCreate(msgSpaceId externId, int poolIdx, int buffNb, int buffSize);
|
||||||
/* poolDataTabClose.c */
|
/* poolDataTabClose.c */
|
||||||
int msgPoolDataTabClose(msgSpace * space, void *addr);
|
int msgPoolDataTabClose(msgSpace *space, void *addr);
|
||||||
/* poolDataTabCreate.c */
|
/* poolDataTabCreate.c */
|
||||||
void *msgPoolDataTabCreate(msgSpace * space);
|
void *msgPoolDataTabCreate(msgSpace *space);
|
||||||
/* poolDataTabLock.c */
|
/* poolDataTabLock.c */
|
||||||
int msgPoolDataTabLock(msgSpace * space);
|
int msgPoolDataTabLock(msgSpace *space);
|
||||||
/* poolDataTabOpen.c */
|
/* poolDataTabOpen.c */
|
||||||
void *msgPoolDataTabOpen(msgSpace * space);
|
void *msgPoolDataTabOpen(msgSpace *space);
|
||||||
/* poolDataTabUnlock.c */
|
/* poolDataTabUnlock.c */
|
||||||
int msgPoolDataTabUnlock(msgSpace * space);
|
int msgPoolDataTabUnlock(msgSpace *space);
|
||||||
/* poolDelete.c */
|
/* poolDelete.c */
|
||||||
int msgPoolDelete(msgSpaceId spaceId, int poolIdx);
|
int msgPoolDelete(msgSpaceId spaceId, int poolIdx);
|
||||||
/* put.c */
|
/* put.c */
|
||||||
int msgPut(msgSpace * space, int queueIndex, void *addr);
|
int msgPut(msgSpace *space, int queueIndex, void *addr);
|
||||||
/* queueAdd.c */
|
/* queueAdd.c */
|
||||||
int msgQueueAdd(msgQueue * queue, msgQueueElemId newElemId);
|
int msgQueueAdd(msgQueue *queue, msgQueueElemId newElemId);
|
||||||
/* queueClose.c */
|
/* queueClose.c */
|
||||||
int msgQueueClose(msgQueue * queue);
|
int msgQueueClose(msgQueue *queue);
|
||||||
/* queueDelete.c */
|
/* queueDelete.c */
|
||||||
int msgQueueDelete(msgQueueId externId, int queueIdx);
|
int msgQueueDelete(msgQueueId externId, int queueIdx);
|
||||||
/* queueElemClose.c */
|
/* queueElemClose.c */
|
||||||
int msgQueueElemClose(msgQueueElem * queueElem);
|
int msgQueueElemClose(msgQueueElem *queueElem);
|
||||||
/* queueElemCreate.c */
|
/* queueElemCreate.c */
|
||||||
int msgQueueElemCreate(msgQueueElemId finalQueueElemId, msgQueueId queueId,
|
int msgQueueElemCreate(msgQueueElemId finalQueueElemId, msgQueueId queueId, int counter);
|
||||||
int counter);
|
|
||||||
/* queueElemDelete.c */
|
/* queueElemDelete.c */
|
||||||
int msgQueueElemDelete(msgQueueElemId queueElemId);
|
int msgQueueElemDelete(msgQueueElemId queueElemId);
|
||||||
/* queueElemOpen.c */
|
/* queueElemOpen.c */
|
||||||
|
@ -92,22 +81,21 @@ int msgQueueReadTryLock(msgSpaceId externId, int queueIdx);
|
||||||
/* queueReadUnlock.c */
|
/* queueReadUnlock.c */
|
||||||
int msgQueueReadUnlock(msgSpaceId externId, int queueIdx);
|
int msgQueueReadUnlock(msgSpaceId externId, int queueIdx);
|
||||||
/* queueRem.c */
|
/* queueRem.c */
|
||||||
int msgQueueRem(msgQueue * queue, msgQueueElemId oldElemId);
|
int msgQueueRem(msgQueue *queue, msgQueueElemId oldElemId);
|
||||||
/* spaceClose.c */
|
/* spaceClose.c */
|
||||||
int msgSpaceClose(msgSpace * space);
|
int msgSpaceClose(msgSpace *space);
|
||||||
/* spaceCreate.c */
|
/* spaceCreate.c */
|
||||||
msgSpace *msgSpaceCreate(msgSpaceId externId, int queueNb, int poolNb,
|
msgSpace *msgSpaceCreate(msgSpaceId externId, int queueNb, int poolNb, msgPool *poolInfos);
|
||||||
msgPool * poolInfos);
|
|
||||||
/* spaceDelete.c */
|
/* spaceDelete.c */
|
||||||
int msgSpaceDelete(msgSpaceId externId);
|
int msgSpaceDelete(msgSpaceId externId);
|
||||||
/* spaceListAdd.c */
|
/* spaceListAdd.c */
|
||||||
int msgSpaceListAdd(msgSpaceListElemId newElemId);
|
int msgSpaceListAdd(msgSpaceListElemId newElemId);
|
||||||
/* spaceListClose.c */
|
/* spaceListClose.c */
|
||||||
int msgSpaceListClose(msgSpaceList * list);
|
int msgSpaceListClose(msgSpaceList *list);
|
||||||
/* spaceListElemClose.c */
|
/* spaceListElemClose.c */
|
||||||
int msgSpaceListElemClose(msgSpaceListElem * listElem);
|
int msgSpaceListElemClose(msgSpaceListElem *listElem);
|
||||||
/* spaceListElemCreate.c */
|
/* spaceListElemCreate.c */
|
||||||
int msgSpaceListElemCreate(msgSpaceListElemId listElemId, msgSpace * space);
|
int msgSpaceListElemCreate(msgSpaceListElemId listElemId, msgSpace *space);
|
||||||
/* spaceListElemLink.c */
|
/* spaceListElemLink.c */
|
||||||
/* spaceListElemOpen.c */
|
/* spaceListElemOpen.c */
|
||||||
void *msgSpaceListElemOpen(msgSpaceListElemId listElemId);
|
void *msgSpaceListElemOpen(msgSpaceListElemId listElemId);
|
||||||
|
|
118
src/proto.h~
118
src/proto.h~
|
@ -1,118 +0,0 @@
|
||||||
#ifndef _NZG_PROTO
|
|
||||||
#define _NZG_PROTO 1
|
|
||||||
|
|
||||||
/* allocate.c */
|
|
||||||
void *msgAllocate(msgSpace *space, int pool, int taille, int option);
|
|
||||||
/* bufferAttachProc.c */
|
|
||||||
int msgBufferAttachProc(msgPoolData *poolDataTabAddr, int poolIndex, int bufferIndex, void *addr);
|
|
||||||
/* buffer.c */
|
|
||||||
int msgBufferGetAttachedProcIndex(msgPoolData *poolDataTabAddr, int poolIndex, void *addr);
|
|
||||||
/* bufferDetachProc.c */
|
|
||||||
int msgBufferDetachProc(msgPoolData *poolDataTabAddr, int poolIndex, int bufferIndex, void *addr);
|
|
||||||
/* bufferGetFreeIndex.c */
|
|
||||||
int msgBufferGetFreeIndex(msgPoolData *poolDataTabAddr, int poolIndex);
|
|
||||||
/* bufferGetProcAttach.c */
|
|
||||||
int msgBufferGetProcAttach(msgPoolData *poolDataTabAddr, int poolNb, int *poolIndex, int *bufferIndex, void *addr);
|
|
||||||
/* bufferInfoTabCreate.c */
|
|
||||||
int msgBufferInfoTabCreate(msgSpaceId externId, msgPoolData *poolDataTabAddr, int poolIdx, int bufferNb);
|
|
||||||
/* bufferInfoTabInit.c */
|
|
||||||
int msgBufferInfoTabInit(msgPoolData *poolDataTabAddr, int poolIndex);
|
|
||||||
/* bufferMap.c */
|
|
||||||
void *msgBufferMap(msgPoolData *poolDataTab, int poolIndex, int bufferIndex);
|
|
||||||
/* free.c */
|
|
||||||
int msgFree(msgSpace *space, void *addr);
|
|
||||||
/* get.c */
|
|
||||||
void *msgGet(msgSpace *space, int queueIndex, int option);
|
|
||||||
/* ids.c */
|
|
||||||
int msgSpaceIdIntern(msgSpaceId dest, const msgSpaceId src);
|
|
||||||
int msgPoolDataTabSemIdIntern(msgPoolSemId destSemId, const msgSpaceId externId);
|
|
||||||
int msgPoolSemIdIntern(msgPoolSemId destSemId, const msgSpaceId srcPoolId, int poolIdx);
|
|
||||||
int msgPoolDataIdIntern(msgPoolDataTabId dest, const msgSpaceId src);
|
|
||||||
int msgPoolIdIntern(msgPoolId dest, msgPoolId src, int num);
|
|
||||||
int msgBufferInfoTabIdIntern(msgBufferInfoTabId dest, msgSpaceId src, int num);
|
|
||||||
int msgQueueProtSemIdIntern(msgQueueSemId dest, msgSpaceId externId, int queueIdx);
|
|
||||||
int msgQueueReadSemIdIntern(msgQueueSemId dest, msgSpaceId externId, int queueIdx);
|
|
||||||
int msgQueueIdIntern(msgQueueId dest, msgSpaceId externId, int queueIdx);
|
|
||||||
int msgQueueElemIdIntern(msgQueueElemId dest, msgQueueId src, int counter);
|
|
||||||
int msgSpaceListElemIdIntern(msgSpaceListElemId elemListId, msgSpaceId externId);
|
|
||||||
/* list.c */
|
|
||||||
/* poolCreate.c */
|
|
||||||
int msgPoolCreate(msgSpaceId externId, int poolIdx, int buffNb, int buffSize);
|
|
||||||
/* poolDataTabClose.c */
|
|
||||||
int msgPoolDataTabClose(msgSpace *space, void *addr);
|
|
||||||
/* poolDataTabCreate.c */
|
|
||||||
void *msgPoolDataTabCreate(msgSpace *space);
|
|
||||||
/* poolDataTabLock.c */
|
|
||||||
int msgPoolDataTabLock(msgSpace *space);
|
|
||||||
/* poolDataTabOpen.c */
|
|
||||||
void *msgPoolDataTabOpen(msgSpace *space);
|
|
||||||
/* poolDataTabUnlock.c */
|
|
||||||
int msgPoolDataTabUnlock(msgSpace *space);
|
|
||||||
/* poolDelete.c */
|
|
||||||
int msgPoolDelete(msgSpaceId spaceId, int poolIdx);
|
|
||||||
/* put.c */
|
|
||||||
int msgPut(msgSpace *space, int queueIndex, void *addr);
|
|
||||||
/* queueAdd.c */
|
|
||||||
int msgQueueAdd(msgQueue *queue, msgQueueElemId newElemId);
|
|
||||||
/* queueClose.c */
|
|
||||||
int msgQueueClose(msgQueue *queue);
|
|
||||||
/* queueDelete.c */
|
|
||||||
int msgQueueDelete(msgQueueId externId, int queueIdx);
|
|
||||||
/* queueElemClose.c */
|
|
||||||
int msgQueueElemClose(msgQueueElem *queueElem);
|
|
||||||
/* queueElemCreate.c */
|
|
||||||
int msgQueueElemCreate(msgQueueElemId finalQueueElemId, msgQueueId queueId, int counter);
|
|
||||||
/* queueElemDelete.c */
|
|
||||||
int msgQueueElemDelete(msgQueueElemId queueElemId);
|
|
||||||
/* queueElemOpen.c */
|
|
||||||
void *msgQueueElemOpen(msgQueueElemId queueElemId);
|
|
||||||
/* queueInit.c */
|
|
||||||
msgQueue *msgQueueInit(msgSpaceId externId, int queueIdx);
|
|
||||||
/* queueOpen.c */
|
|
||||||
void *msgQueueOpen(msgQueueId queueId);
|
|
||||||
/* queueProtLock.c */
|
|
||||||
int msgQueueProtLock(msgSpaceId externId, int queueIdx);
|
|
||||||
/* queueProtUnlock.c */
|
|
||||||
int msgQueueProtUnlock(msgSpaceId externId, int queueIdx);
|
|
||||||
/* queueReadLock.c */
|
|
||||||
int msgQueueReadLock(msgSpaceId externId, int queueIdx);
|
|
||||||
/* queueReadTryLock.c */
|
|
||||||
int msgQueueReadTryLock(msgSpaceId externId, int queueIdx);
|
|
||||||
/* queueReadUnlock.c */
|
|
||||||
int msgQueueReadUnlock(msgSpaceId externId, int queueIdx);
|
|
||||||
/* queueRem.c */
|
|
||||||
int msgQueueRem(msgQueue *queue, msgQueueElemId oldElemId);
|
|
||||||
/* spaceClose.c */
|
|
||||||
int msgSpaceClose(msgSpace *space);
|
|
||||||
/* spaceCreate.c */
|
|
||||||
msgSpace *msgSpaceCreate(msgSpaceId externId, int queueNb, int poolNb, msgPool *poolInfos);
|
|
||||||
/* spaceDelete.c */
|
|
||||||
int msgSpaceDelete(msgSpaceId externId);
|
|
||||||
/* spaceListAdd.c */
|
|
||||||
int msgSpaceListAdd(msgSpaceListElemId newElemId);
|
|
||||||
/* spaceListClose.c */
|
|
||||||
int msgSpaceListClose(msgSpaceList *list);
|
|
||||||
/* spaceListElemClose.c */
|
|
||||||
int msgSpaceListElemClose(msgSpaceListElem *listElem);
|
|
||||||
/* spaceListElemCreate.c */
|
|
||||||
int msgSpaceListElemCreate(msgSpaceListElemId listElemId, msgSpace *space);
|
|
||||||
/* spaceListElemLink.c */
|
|
||||||
/* spaceListElemOpen.c */
|
|
||||||
void *msgSpaceListElemOpen(msgSpaceListElemId listElemId);
|
|
||||||
/* spaceListFindId.c */
|
|
||||||
int msgSpaceListFindId(msgSpaceId externId);
|
|
||||||
int msgSpaceListElemFindId(msgSpaceListElemId elemId, msgSpaceId spaceId);
|
|
||||||
/* spaceListInit.c */
|
|
||||||
int msgSpaceListInit(void);
|
|
||||||
/* spaceListLocking.c */
|
|
||||||
int msgSpaceListLock(void);
|
|
||||||
int msgSpaceListUnlock(void);
|
|
||||||
/* spaceListOpen.c */
|
|
||||||
void *msgSpaceListOpen(void);
|
|
||||||
/* spaceListRem.c */
|
|
||||||
int msgSpaceListRem(msgSpaceId spaceId);
|
|
||||||
/* spaceOpen.c */
|
|
||||||
msgSpace *msgSpaceOpen(msgSpaceId externId);
|
|
||||||
/* spaceState.c */
|
|
||||||
|
|
||||||
#endif
|
|
112
src/put.c
112
src/put.c
|
@ -1,66 +1,70 @@
|
||||||
#include "libnazgul.h"
|
#include "libnazgul.h"
|
||||||
|
|
||||||
int msgPut(msgSpace * space, int queueIndex, void *addr)
|
int msgPut(msgSpace * space,int queueIndex, void * addr){
|
||||||
{
|
// retrouver le pool, buffer qui correspondent à l'addresse...
|
||||||
// retrouver le pool, buffer qui correspondent à l'addresse...
|
msgPoolData * poolDataTabAddr;
|
||||||
msgPoolData *poolDataTabAddr;
|
int poolIndex;
|
||||||
int poolIndex;
|
int bufferIndex;
|
||||||
int bufferIndex;
|
int err;
|
||||||
int err;
|
msgQueueElemId newElemId;
|
||||||
msgQueueElemId newElemId;
|
msgQueueElem * queueElem;
|
||||||
msgQueueElem *queueElem;
|
msgQueueId queueId;
|
||||||
msgQueueId queueId;
|
msgQueue * queue;
|
||||||
msgQueue *queue;
|
|
||||||
|
|
||||||
msgPoolDataTabLock(space);
|
msgPoolDataTabLock(space);
|
||||||
poolDataTabAddr = msgPoolDataTabOpen(space);
|
poolDataTabAddr=msgPoolDataTabOpen(space);
|
||||||
if (poolDataTabAddr == NULL) {
|
if (poolDataTabAddr == NULL){
|
||||||
NZG_ERROR("msgPoolDataTabOpen", space->poolDataTabId);
|
NZG_ERROR("msgPoolDataTabOpen",space->poolDataTabId);
|
||||||
goto ERROR;
|
goto ERROR;
|
||||||
}
|
}
|
||||||
err = msgBufferGetProcAttach(poolDataTabAddr,
|
err=msgBufferGetProcAttach(
|
||||||
space->poolNb,
|
poolDataTabAddr,
|
||||||
&poolIndex, &bufferIndex, addr);
|
space->poolNb,
|
||||||
if (err) {
|
&poolIndex,
|
||||||
//FIXME
|
&bufferIndex,
|
||||||
}
|
addr
|
||||||
// ouvrir la queue avec le bon index
|
);
|
||||||
msgQueueIdIntern(queueId, space->externId, queueIndex);
|
|
||||||
|
|
||||||
msgQueueProtLock(space->externId, queueIndex);
|
// ouvrir la queue avec le bon index
|
||||||
queue = msgQueueOpen(queueId);
|
msgQueueIdIntern(queueId,space->externId,queueIndex);
|
||||||
|
|
||||||
// creer un element vide
|
msgQueueProtLock(space->externId,queueIndex);
|
||||||
|
queue = msgQueueOpen(queueId);
|
||||||
|
|
||||||
msgQueueElemCreate(newElemId, queueId, queue->elemCounter);
|
// creer un element vide
|
||||||
// ouvrir l'element
|
|
||||||
queueElem = msgQueueElemOpen(newElemId);
|
|
||||||
|
|
||||||
// modifier les index pour retrouver le buffer
|
msgQueueElemCreate(newElemId,queueId,queue->elemCounter);
|
||||||
queueElem->poolIndex = poolIndex;
|
// ouvrir l'element
|
||||||
queueElem->bufferIndex = bufferIndex;
|
queueElem=msgQueueElemOpen(newElemId);
|
||||||
|
|
||||||
// fermer l'element
|
// modifier les index pour retrouver le buffer
|
||||||
if (msgQueueElemClose(queueElem) < 0) {
|
queueElem->poolIndex=poolIndex;
|
||||||
NZG_ERROR("msgQueueElemClose", "");
|
queueElem->bufferIndex=bufferIndex;
|
||||||
goto ERROR;
|
|
||||||
}
|
|
||||||
//ajouter le message a la bonne file...
|
|
||||||
if (msgQueueAdd(queue, newElemId) < 0) {
|
|
||||||
NZG_ERROR("msgQueueAdd", newElemId);
|
|
||||||
goto ERROR;
|
|
||||||
}
|
|
||||||
// fermer la file
|
|
||||||
msgQueueClose(queue);
|
|
||||||
msgQueueProtUnlock(space->externId, queueIndex);
|
|
||||||
|
|
||||||
msgPoolDataTabClose(space, poolDataTabAddr);
|
// fermer l'element
|
||||||
msgPoolDataTabUnlock(space);
|
if (msgQueueElemClose(queueElem) <0 ){
|
||||||
|
NZG_ERROR("msgQueueElemClose","");
|
||||||
|
goto ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
// on laisse une nouvelle ressource de la liste au get
|
//ajouter le message a la bonne file...
|
||||||
msgQueueReadUnlock(space->externId, queueIndex);
|
if (msgQueueAdd(queue,newElemId) < 0){
|
||||||
return 0;
|
NZG_ERROR("msgQueueAdd",newElemId);
|
||||||
|
goto ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
ERROR:
|
// fermer la file
|
||||||
return -1;
|
msgQueueClose(queue);
|
||||||
|
msgQueueProtUnlock(space->externId,queueIndex);
|
||||||
|
|
||||||
|
msgPoolDataTabClose(space,poolDataTabAddr);
|
||||||
|
msgPoolDataTabUnlock(space);
|
||||||
|
|
||||||
|
// on laisse une nouvelle ressource de la liste au get
|
||||||
|
msgQueueReadUnlock(space->externId,queueIndex);
|
||||||
|
return 0;
|
||||||
|
ERROR:
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -2,48 +2,47 @@
|
||||||
|
|
||||||
// on ajoute en fin de queue...
|
// on ajoute en fin de queue...
|
||||||
|
|
||||||
int msgQueueAdd(msgQueue * queue, msgQueueElemId newElemId)
|
int msgQueueAdd(msgQueue * queue, msgQueueElemId newElemId){
|
||||||
{
|
msgQueueElem * queueOldTailElem;
|
||||||
msgQueueElem *queueOldTailElem;
|
msgQueueElem * queueNewTailElem;
|
||||||
msgQueueElem *queueNewTailElem;
|
|
||||||
|
|
||||||
// on informe l'element qu'il est le dernier
|
// on informe l'element qu'il est le dernier
|
||||||
queueNewTailElem = msgQueueElemOpen(newElemId);
|
queueNewTailElem=msgQueueElemOpen(newElemId);
|
||||||
if (queueNewTailElem == NULL) {
|
if (queueNewTailElem == NULL){
|
||||||
NZG_ERROR("msgQueueElemOpen", newElemId);
|
NZG_ERROR("msgQueueElemOpen",newElemId);
|
||||||
goto ERROR;
|
goto ERROR;
|
||||||
}
|
|
||||||
strcpy(queueNewTailElem->next, newElemId);
|
|
||||||
if (msgQueueElemClose(queueNewTailElem) < 0) {
|
|
||||||
NZG_ERROR("msgQueueElemClose", newElemId);
|
|
||||||
goto ERROR;
|
|
||||||
}
|
}
|
||||||
|
strcpy(queueNewTailElem->next,newElemId);
|
||||||
|
if (msgQueueElemClose(queueNewTailElem) <0 ){
|
||||||
|
NZG_ERROR("msgQueueElemClose",newElemId);
|
||||||
|
goto ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
/* TODO: verifier si la liste n'est pas vide... */
|
/* TODO: verifier si la liste n'est pas vide... */
|
||||||
if ((strcmp(queue->headId, queue->id) == 0)
|
if((strcmp(queue->headId,queue->id)==0)
|
||||||
&& (strcmp(queue->tailId, queue->id) == 0)) {
|
&& (strcmp(queue->tailId,queue->id)==0)) {
|
||||||
printf("- premier elem de queue -\n");
|
printf("- premier elem de queue -\n");
|
||||||
// on donne a la queue l'id de l'element
|
// on donne a la queue l'id de l'element
|
||||||
strcpy(queue->headId, newElemId);
|
strcpy(queue->headId,newElemId);
|
||||||
strcpy(queue->tailId, newElemId);
|
strcpy(queue->tailId,newElemId);
|
||||||
} else {
|
} else {
|
||||||
/* on informe son prédecesseur qu'il a un suivant */
|
/* on informe son prédecesseur qu'il a un suivant */
|
||||||
queueOldTailElem = msgQueueElemOpen(queue->tailId);
|
queueOldTailElem=msgQueueElemOpen(queue->tailId);
|
||||||
if (queueOldTailElem == NULL) {
|
if (queueOldTailElem == NULL){
|
||||||
NZG_ERROR("msgQueueElemOpen", queue->tailId);
|
NZG_ERROR("msgQueueElemOpen",queue->tailId);
|
||||||
goto ERROR;
|
goto ERROR;
|
||||||
}
|
}
|
||||||
strcpy(queueOldTailElem->next, newElemId);
|
strcpy(queueOldTailElem->next,newElemId);
|
||||||
if (msgQueueElemClose(queueOldTailElem) < 0) {
|
if (msgQueueElemClose(queueOldTailElem) < 0){
|
||||||
NZG_ERROR("msgQueueElemClose", queue->tailId);
|
NZG_ERROR("msgQueueElemClose",queue->tailId);
|
||||||
goto ERROR;
|
goto ERROR;
|
||||||
}
|
}
|
||||||
// on donne a la queue l'id du dernier element
|
// on donne a la queue l'id du dernier element
|
||||||
strcpy(queue->tailId, newElemId);
|
strcpy(queue->tailId,newElemId);
|
||||||
}
|
}
|
||||||
// on incremente elemCounter
|
// on incremente elemCounter
|
||||||
queue->elemCounter++;
|
queue->elemCounter++;
|
||||||
return 0;
|
return 0;
|
||||||
ERROR:
|
ERROR:
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,17 +1,16 @@
|
||||||
#include "libnazgul.h"
|
#include "libnazgul.h"
|
||||||
#include "ids.h"
|
#include "ids.h"
|
||||||
|
|
||||||
int msgQueueClose(msgQueue * queue)
|
int msgQueueClose(msgQueue * queue){
|
||||||
{
|
msgQueueId qId;
|
||||||
msgQueueId qId;
|
strcpy(qId,queue->id);
|
||||||
strcpy(qId, queue->id);
|
|
||||||
|
if (munmap(queue,sizeof(msgQueue)) < 0){
|
||||||
|
NZG_ERROR("unmap",qId);
|
||||||
|
goto ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
if (munmap(queue, sizeof(msgQueue)) < 0) {
|
return 0;
|
||||||
NZG_ERROR("unmap", qId);
|
ERROR:
|
||||||
goto ERROR;
|
return -1;
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
ERROR:
|
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,34 +1,35 @@
|
||||||
#include "libnazgul.h"
|
#include "libnazgul.h"
|
||||||
|
|
||||||
int msgQueueDelete(msgQueueId externId, int queueIdx)
|
int msgQueueDelete(msgQueueId externId,int queueIdx){
|
||||||
{
|
msgQueue * queue;
|
||||||
msgQueue *queue;
|
msgQueueId queueId;
|
||||||
msgQueueId queueId;
|
msgQueueSemId queueProtLockSemId;
|
||||||
msgQueueSemId queueProtLockSemId;
|
msgQueueSemId queueReadLockSemId;
|
||||||
msgQueueSemId queueReadLockSemId;
|
|
||||||
|
msgQueueIdIntern(queueId,externId,queueIdx);
|
||||||
|
queue = msgQueueOpen(queueId);
|
||||||
|
|
||||||
msgQueueIdIntern(queueId, externId, queueIdx);
|
if (strcmp(queue->headId,queue->id)!=0){
|
||||||
queue = msgQueueOpen(queueId);
|
// liste non-vide
|
||||||
|
if (msgQueueElemDelete(queue->headId) <0){
|
||||||
if (strcmp(queue->headId, queue->id) != 0) {
|
NZG_ERROR("msgQueueElemDelete",queue->headId);
|
||||||
// liste non-vide
|
goto ERROR;
|
||||||
if (msgQueueElemDelete(queue->headId) < 0) {
|
|
||||||
NZG_ERROR("msgQueueElemDelete", queue->headId);
|
|
||||||
goto ERROR;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
msgQueueProtSemIdIntern(queueProtLockSemId,externId,queueIdx);
|
||||||
|
msgQueueReadSemIdIntern(queueReadLockSemId,externId,queueIdx);
|
||||||
|
sem_unlink(queueProtLockSemId);
|
||||||
|
sem_unlink(queueReadLockSemId);
|
||||||
|
|
||||||
msgQueueProtSemIdIntern(queueProtLockSemId, externId, queueIdx);
|
if (shm_unlink(queueId) < 0){
|
||||||
msgQueueReadSemIdIntern(queueReadLockSemId, externId, queueIdx);
|
NZG_ERROR("shm_unlink msgQueueElem",queueId);
|
||||||
sem_unlink(queueProtLockSemId);
|
goto ERROR;
|
||||||
sem_unlink(queueReadLockSemId);
|
}
|
||||||
|
|
||||||
if (shm_unlink(queueId) < 0) {
|
return 0;
|
||||||
NZG_ERROR("shm_unlink msgQueueElem", queueId);
|
ERROR:
|
||||||
goto ERROR;
|
return -1;
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
ERROR:
|
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,16 +1,15 @@
|
||||||
#include "libnazgul.h"
|
#include "libnazgul.h"
|
||||||
|
|
||||||
int msgQueueElemClose(msgQueueElem * queueElem)
|
int msgQueueElemClose(msgQueueElem * queueElem){
|
||||||
{
|
msgQueueElemId qId;
|
||||||
msgQueueElemId qId;
|
strcpy(qId,queueElem->id);
|
||||||
strcpy(qId, queueElem->id);
|
|
||||||
|
if (munmap(queueElem,sizeof(msgQueueElem)) < 0){
|
||||||
|
NZG_ERROR("unmap",qId);
|
||||||
|
goto ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
if (munmap(queueElem, sizeof(msgQueueElem)) < 0) {
|
return 0;
|
||||||
NZG_ERROR("unmap", qId);
|
ERROR:
|
||||||
goto ERROR;
|
return -1;
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
ERROR:
|
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,30 +1,31 @@
|
||||||
#include "libnazgul.h"
|
#include "libnazgul.h"
|
||||||
#include "ids.h"
|
#include "ids.h"
|
||||||
|
|
||||||
int msgQueueElemCreate(msgQueueElemId finalQueueElemId,
|
int msgQueueElemCreate(
|
||||||
msgQueueId queueId, int counter)
|
msgQueueElemId finalQueueElemId ,
|
||||||
{
|
msgQueueId queueId,
|
||||||
msgQueueElemId queueElemId;
|
int counter){
|
||||||
int queueElemFd;
|
msgQueueElemId queueElemId;
|
||||||
|
int queueElemFd;
|
||||||
|
|
||||||
msgQueueElemIdIntern(queueElemId, queueId, counter);
|
msgQueueElemIdIntern(queueElemId,queueId,counter);
|
||||||
strcpy(finalQueueElemId, queueElemId);
|
strcpy(finalQueueElemId,queueElemId);
|
||||||
|
|
||||||
queueElemFd = shm_open(queueElemId,
|
queueElemFd=shm_open(queueElemId,
|
||||||
O_RDWR | O_CREAT | O_EXCL | O_TRUNC,
|
O_RDWR|O_CREAT|O_EXCL|O_TRUNC,
|
||||||
SHM_DEFAULT_MODE);
|
SHM_DEFAULT_MODE);
|
||||||
if (queueElemFd == -1) {
|
if (queueElemFd == -1 ) {
|
||||||
NZG_ERROR("shm_open : msgQueueElem creation", queueElemId);
|
NZG_ERROR("shm_open : msgQueueElem creation",queueElemId);
|
||||||
goto ERROR;
|
goto ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ftruncate(queueElemFd, sizeof(msgQueueElem)) < 0) {
|
if (ftruncate(queueElemFd, sizeof(msgQueueElem)) < 0){
|
||||||
NZG_ERROR("ftruncate", queueElemId);
|
NZG_ERROR("ftruncate", queueElemId);
|
||||||
goto ERROR;
|
goto ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
close(queueElemFd);
|
close(queueElemFd);
|
||||||
return 0;
|
return 0;
|
||||||
ERROR:
|
ERROR:
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,33 +1,33 @@
|
||||||
#include "libnazgul.h"
|
#include "libnazgul.h"
|
||||||
|
|
||||||
int msgQueueElemDelete(msgQueueElemId queueElemId)
|
int msgQueueElemDelete(msgQueueElemId queueElemId){
|
||||||
{
|
msgQueueElem * queueElem;
|
||||||
msgQueueElem *queueElem;
|
msgQueueElemId nextIdToDie;
|
||||||
msgQueueElemId nextIdToDie;
|
|
||||||
|
queueElem = msgQueueElemOpen(queueElemId);
|
||||||
|
if (queueElem==NULL){
|
||||||
|
NZG_ERROR("msgQueueElemOpen",queueElemId);
|
||||||
|
goto ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
queueElem = msgQueueElemOpen(queueElemId);
|
strcpy(nextIdToDie, queueElem->next);
|
||||||
if (queueElem == NULL) {
|
|
||||||
NZG_ERROR("msgQueueElemOpen", queueElemId);
|
if (msgQueueElemClose(queueElem) < 0){
|
||||||
goto ERROR;
|
NZG_ERROR("msgQueueElemClose",queueElemId);
|
||||||
}
|
goto ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
strcpy(nextIdToDie, queueElem->next);
|
// on détruit l'élément
|
||||||
|
shm_unlink(queueElemId);
|
||||||
|
|
||||||
if (msgQueueElemClose(queueElem) < 0) {
|
if (nextIdToDie != queueElemId){
|
||||||
NZG_ERROR("msgQueueElemClose", queueElemId);
|
return msgQueueElemDelete(nextIdToDie);
|
||||||
goto ERROR;
|
} else {
|
||||||
}
|
printf("msgQueueElemDelete: EOL reached \n");
|
||||||
// on détruit l'élément
|
// element unique...
|
||||||
shm_unlink(queueElemId);
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
if (nextIdToDie != queueElemId) {
|
ERROR:
|
||||||
return msgQueueElemDelete(nextIdToDie);
|
return -1;
|
||||||
} else {
|
|
||||||
printf("msgQueueElemDelete: EOL reached \n");
|
|
||||||
// element unique...
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
ERROR:
|
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,28 +1,29 @@
|
||||||
#include "libnazgul.h"
|
#include "libnazgul.h"
|
||||||
#include "ids.h"
|
#include "ids.h"
|
||||||
|
|
||||||
void *msgQueueElemOpen(msgQueueElemId queueElemId)
|
void * msgQueueElemOpen(msgQueueElemId queueElemId){
|
||||||
{
|
int queueElemFd;
|
||||||
int queueElemFd;
|
void * queueElemAddr;
|
||||||
void *queueElemAddr;
|
|
||||||
|
|
||||||
queueElemFd = shm_open(queueElemId, O_RDWR, SHM_DEFAULT_MODE);
|
queueElemFd=shm_open(queueElemId,O_RDWR,SHM_DEFAULT_MODE);
|
||||||
if (queueElemFd == -1) {
|
if (queueElemFd == -1 ) {
|
||||||
NZG_ERROR("shm_open : msgQueue open", queueElemId);
|
NZG_ERROR("shm_open : msgQueue open",queueElemId);
|
||||||
goto ERROR;
|
goto ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
queueElemAddr = mmap(NULL,
|
queueElemAddr=mmap(NULL,
|
||||||
sizeof(msgQueueElem),
|
sizeof(msgQueueElem),
|
||||||
PROT_READ | PROT_WRITE,
|
PROT_READ|PROT_WRITE,
|
||||||
MAP_SHARED, queueElemFd, 0);
|
MAP_SHARED,
|
||||||
if (queueElemAddr == MAP_FAILED) {
|
queueElemFd,
|
||||||
NZG_ERROR("mmap", queueElemId);
|
0);
|
||||||
goto ERROR;
|
if( queueElemAddr == MAP_FAILED ) {
|
||||||
}
|
NZG_ERROR("mmap",queueElemId);
|
||||||
|
goto ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
close(queueElemFd);
|
close(queueElemFd);
|
||||||
return queueElemAddr;
|
return queueElemAddr;
|
||||||
ERROR:
|
ERROR:
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,34 +1,35 @@
|
||||||
#include "libnazgul.h"
|
#include "libnazgul.h"
|
||||||
#include "ids.h"
|
#include "ids.h"
|
||||||
|
|
||||||
msgQueue *msgQueueInit(msgSpaceId externId, int queueIdx)
|
msgQueue * msgQueueInit(msgSpaceId externId, int queueIdx) {
|
||||||
{
|
|
||||||
int queueFd;
|
int queueFd;
|
||||||
msgQueue *queue;
|
msgQueue * queue;
|
||||||
sem_t *semProtectFd;
|
sem_t * semProtectFd;
|
||||||
msgQueueSemId queueSemProtectId;
|
msgQueueSemId queueSemProtectId;
|
||||||
sem_t *semReadableFd;
|
sem_t * semReadableFd;
|
||||||
msgQueueSemId queueSemReadableId;
|
msgQueueSemId queueSemReadableId;
|
||||||
msgQueueId queueId;
|
msgQueueId queueId;
|
||||||
|
|
||||||
queue = NULL;
|
queue = NULL;
|
||||||
|
|
||||||
msgQueueProtSemIdIntern(queueSemProtectId, externId, queueIdx);
|
|
||||||
msgQueueReadSemIdIntern(queueSemReadableId, externId, queueIdx);
|
msgQueueProtSemIdIntern(queueSemProtectId,externId,queueIdx);
|
||||||
|
msgQueueReadSemIdIntern(queueSemReadableId,externId,queueIdx);
|
||||||
|
|
||||||
// creation du semaphore de lecture
|
// creation du semaphore de lecture
|
||||||
semReadableFd = sem_open(queueSemReadableId,
|
semReadableFd = sem_open(queueSemReadableId,
|
||||||
O_CREAT | O_EXCL, SEM_DEFAULT_MODE, 0);
|
O_CREAT|O_EXCL, SEM_DEFAULT_MODE, 0);
|
||||||
if (semReadableFd == SEM_FAILED) {
|
if(semReadableFd == SEM_FAILED) {
|
||||||
NZG_ERROR("sem_open", queueSemReadableId);
|
NZG_ERROR("sem_open", queueSemReadableId);
|
||||||
goto ERROR;
|
goto ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
// creation du semaphore de protection
|
// creation du semaphore de protection
|
||||||
semProtectFd = sem_open(queueSemProtectId,
|
semProtectFd = sem_open(queueSemProtectId,
|
||||||
O_CREAT | O_EXCL, SEM_DEFAULT_MODE, 0);
|
O_CREAT|O_EXCL, SEM_DEFAULT_MODE, 0);
|
||||||
if (semProtectFd == SEM_FAILED) {
|
if(semProtectFd == SEM_FAILED) {
|
||||||
NZG_ERROR("sem_open", queueSemProtectId);
|
NZG_ERROR("sem_open", queueSemProtectId);
|
||||||
goto ERROR;
|
goto ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* if(sem_wait(semProtectFd)==-1){
|
/* if(sem_wait(semProtectFd)==-1){
|
||||||
|
@ -36,36 +37,35 @@ msgQueue *msgQueueInit(msgSpaceId externId, int queueIdx)
|
||||||
goto ERROR;
|
goto ERROR;
|
||||||
} */
|
} */
|
||||||
|
|
||||||
if (msgQueueIdIntern(queueId, externId, queueIdx) < 0) {
|
if(msgQueueIdIntern(queueId, externId, queueIdx) < 0) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
queueFd =
|
queueFd = shm_open(queueId, O_RDWR|O_CREAT|O_EXCL|O_TRUNC, MSGSPACE_DEFAULT_MODE);
|
||||||
shm_open(queueId, O_RDWR | O_CREAT | O_EXCL | O_TRUNC,
|
if(queueFd == -1) {
|
||||||
MSGSPACE_DEFAULT_MODE);
|
NZG_ERROR("shm_open : queueInit",queueId);
|
||||||
if (queueFd == -1) {
|
return NULL;
|
||||||
NZG_ERROR("shm_open : queueInit", queueId);
|
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ftruncate(queueFd, sizeof(msgQueue)) == -1) {
|
if(ftruncate(queueFd, sizeof(msgQueue)) == -1) {
|
||||||
fprintf(stderr, "Queue resizing failed: %s\n", strerror(errno));
|
fprintf( stderr, "Queue resizing failed: %s\n",
|
||||||
return NULL;
|
strerror( errno ) );
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
queue = msgQueueOpen(queueId);
|
queue=msgQueueOpen(queueId);
|
||||||
/* on remplit la structure msgQueue */
|
/* on remplit la structure msgQueue */
|
||||||
queue->elemCounter = 0;
|
queue->elemCounter = 0;
|
||||||
strcpy(queue->id, queueId);
|
strcpy(queue->id,queueId);
|
||||||
strcpy(queue->headId, queue->id);
|
strcpy(queue->headId,queue->id);
|
||||||
strcpy(queue->tailId, queue->id);
|
strcpy(queue->tailId,queue->id);
|
||||||
|
|
||||||
/* on ferme tout ce qu'il faut */
|
/* on ferme tout ce qu'il faut */
|
||||||
close(queueFd);
|
close(queueFd);
|
||||||
msgQueueProtUnlock(externId, queueIdx);
|
msgQueueProtUnlock(externId,queueIdx);
|
||||||
|
|
||||||
return queue;
|
return queue;
|
||||||
ERROR:
|
ERROR:
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,27 +1,29 @@
|
||||||
#include "libnazgul.h"
|
#include "libnazgul.h"
|
||||||
#include "ids.h"
|
#include "ids.h"
|
||||||
|
|
||||||
void *msgQueueOpen(msgQueueId queueId)
|
void * msgQueueOpen(msgQueueId queueId){
|
||||||
{
|
int queueFd;
|
||||||
int queueFd;
|
void * queueAddr;
|
||||||
void *queueAddr;
|
|
||||||
|
|
||||||
queueFd = shm_open(queueId, O_RDWR, SHM_DEFAULT_MODE);
|
queueFd=shm_open(queueId,O_RDWR,SHM_DEFAULT_MODE);
|
||||||
if (queueFd == -1) {
|
if (queueFd == -1 ) {
|
||||||
NZG_ERROR("shm_open : msgQueue open", queueId);
|
NZG_ERROR("shm_open : msgQueue open",queueId);
|
||||||
goto ERROR;
|
goto ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
queueAddr = mmap(NULL,
|
queueAddr=mmap(NULL,
|
||||||
sizeof(msgQueue),
|
sizeof(msgQueue),
|
||||||
PROT_READ | PROT_WRITE, MAP_SHARED, queueFd, 0);
|
PROT_READ|PROT_WRITE,
|
||||||
if (queueAddr == MAP_FAILED) {
|
MAP_SHARED,
|
||||||
NZG_ERROR("mmap", queueId);
|
queueFd,
|
||||||
goto ERROR;
|
0);
|
||||||
}
|
if( queueAddr == MAP_FAILED ) {
|
||||||
|
NZG_ERROR("mmap",queueId);
|
||||||
|
goto ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
close(queueFd);
|
close(queueFd);
|
||||||
return queueAddr;
|
return queueAddr;
|
||||||
ERROR:
|
ERROR:
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,36 +2,32 @@
|
||||||
#include "ids.h"
|
#include "ids.h"
|
||||||
|
|
||||||
#define DEBUG 0
|
#define DEBUG 0
|
||||||
int msgQueueProtLock(msgSpaceId externId, int queueIdx)
|
int msgQueueProtLock(msgSpaceId externId,int queueIdx){
|
||||||
{
|
int semval;
|
||||||
int semval;
|
sem_t * queueSemFd;
|
||||||
sem_t *queueSemFd;
|
msgQueueSemId queueSemId;
|
||||||
msgQueueSemId queueSemId;
|
|
||||||
|
|
||||||
msgQueueProtSemIdIntern(queueSemId, externId, queueIdx);
|
msgQueueProtSemIdIntern(queueSemId,externId,queueIdx);
|
||||||
if (DEBUG) {
|
if (DEBUG) { printf("Locking %s\n",queueSemId);}
|
||||||
printf("Locking %s\n", queueSemId);
|
queueSemFd=sem_open(queueSemId,O_CREAT,SEM_DEFAULT_MODE,1);
|
||||||
}
|
if(queueSemFd==SEM_FAILED){
|
||||||
queueSemFd = sem_open(queueSemId, O_CREAT, SEM_DEFAULT_MODE, 1);
|
NZG_ERROR("sem_open",queueSemId);
|
||||||
if (queueSemFd == SEM_FAILED) {
|
goto ERROR;
|
||||||
NZG_ERROR("sem_open", queueSemId);
|
}
|
||||||
goto ERROR;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (sem_wait(queueSemFd) == -1) {
|
if(sem_wait(queueSemFd)==-1){
|
||||||
NZG_ERROR("sem_wait", queueSemId);
|
NZG_ERROR("sem_wait",queueSemId);
|
||||||
goto ERROR;
|
goto ERROR;
|
||||||
}
|
}
|
||||||
semval = 0;
|
semval=0;
|
||||||
sem_getvalue(queueSemFd, &semval);
|
sem_getvalue(queueSemFd,&semval);
|
||||||
if (DEBUG) {
|
if (DEBUG) { printf("(AfterValue:%d)\n",semval); }
|
||||||
printf("(AfterValue:%d)\n", semval);
|
|
||||||
}
|
|
||||||
|
|
||||||
sem_close(queueSemFd);
|
sem_close(queueSemFd);
|
||||||
sem_close(queueSemFd);
|
sem_close(queueSemFd);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
ERROR:
|
ERROR:
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,36 +3,32 @@
|
||||||
|
|
||||||
#define DEBUG 0
|
#define DEBUG 0
|
||||||
|
|
||||||
int msgQueueProtUnlock(msgSpaceId externId, int queueIdx)
|
int msgQueueProtUnlock(msgSpaceId externId,int queueIdx){
|
||||||
{
|
int semval;
|
||||||
int semval;
|
sem_t * queueSemFd;
|
||||||
sem_t *queueSemFd;
|
msgQueueSemId queueSemId;
|
||||||
msgQueueSemId queueSemId;
|
|
||||||
|
|
||||||
msgQueueProtSemIdIntern(queueSemId, externId, queueIdx);
|
msgQueueProtSemIdIntern(queueSemId,externId,queueIdx);
|
||||||
if (DEBUG) {
|
if (DEBUG) { printf("Unlocking %s\n",queueSemId); }
|
||||||
printf("Unlocking %s\n", queueSemId);
|
|
||||||
}
|
|
||||||
|
|
||||||
queueSemFd = sem_open(queueSemId, O_CREAT, SEM_DEFAULT_MODE, 1);
|
queueSemFd=sem_open(queueSemId,O_CREAT,SEM_DEFAULT_MODE,1);
|
||||||
if (queueSemFd == SEM_FAILED) {
|
if(queueSemFd==SEM_FAILED){
|
||||||
NZG_ERROR("sem_open", queueSemId);
|
NZG_ERROR("sem_open",queueSemId);
|
||||||
goto ERROR;
|
goto ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sem_post(queueSemFd) == -1) {
|
if(sem_post(queueSemFd)==-1){
|
||||||
NZG_ERROR("sem_post", queueSemId);
|
NZG_ERROR("sem_post",queueSemId);
|
||||||
goto ERROR;
|
goto ERROR;
|
||||||
}
|
}
|
||||||
semval = 0;
|
semval=0;
|
||||||
sem_getvalue(queueSemFd, &semval);
|
sem_getvalue(queueSemFd,&semval);
|
||||||
if (DEBUG) {
|
if (DEBUG) { printf("(AfterValue:%d)\n",semval); }
|
||||||
printf("(AfterValue:%d)\n", semval);
|
|
||||||
}
|
|
||||||
|
|
||||||
sem_close(queueSemFd);
|
sem_close(queueSemFd);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
ERROR:
|
ERROR:
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,35 +3,31 @@
|
||||||
|
|
||||||
#define DEBUG 0
|
#define DEBUG 0
|
||||||
|
|
||||||
int msgQueueReadLock(msgSpaceId externId, int queueIdx)
|
int msgQueueReadLock(msgSpaceId externId,int queueIdx){
|
||||||
{
|
int semval;
|
||||||
int semval;
|
sem_t * queueSemFd;
|
||||||
sem_t *queueSemFd;
|
msgQueueSemId queueSemId;
|
||||||
msgQueueSemId queueSemId;
|
|
||||||
|
|
||||||
msgQueueReadSemIdIntern(queueSemId, externId, queueIdx);
|
msgQueueReadSemIdIntern(queueSemId,externId,queueIdx);
|
||||||
if (DEBUG) {
|
if (DEBUG) { printf("Locking %s\n",queueSemId); }
|
||||||
printf("Locking %s\n", queueSemId);
|
queueSemFd=sem_open(queueSemId,O_CREAT,SEM_DEFAULT_MODE,1);
|
||||||
}
|
if(queueSemFd==SEM_FAILED){
|
||||||
queueSemFd = sem_open(queueSemId, O_CREAT, SEM_DEFAULT_MODE, 1);
|
NZG_ERROR("sem_open",queueSemId);
|
||||||
if (queueSemFd == SEM_FAILED) {
|
goto ERROR;
|
||||||
NZG_ERROR("sem_open", queueSemId);
|
}
|
||||||
goto ERROR;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (sem_wait(queueSemFd) == -1) {
|
if(sem_wait(queueSemFd)==-1){
|
||||||
NZG_ERROR("sem_wait", queueSemId);
|
NZG_ERROR("sem_wait",queueSemId);
|
||||||
goto ERROR;
|
goto ERROR;
|
||||||
}
|
}
|
||||||
semval = 0;
|
semval=0;
|
||||||
sem_getvalue(queueSemFd, &semval);
|
sem_getvalue(queueSemFd,&semval);
|
||||||
if (DEBUG) {
|
if (DEBUG) { printf("(AfterValue:%d)\n",semval); }
|
||||||
printf("(AfterValue:%d)\n", semval);
|
|
||||||
}
|
|
||||||
|
|
||||||
sem_close(queueSemFd);
|
sem_close(queueSemFd);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
ERROR:
|
ERROR:
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,35 +3,31 @@
|
||||||
|
|
||||||
#define DEBUG 0
|
#define DEBUG 0
|
||||||
|
|
||||||
int msgQueueReadTryLock(msgSpaceId externId, int queueIdx)
|
int msgQueueReadTryLock(msgSpaceId externId,int queueIdx){
|
||||||
{
|
int semval;
|
||||||
int semval;
|
sem_t * queueSemFd;
|
||||||
sem_t *queueSemFd;
|
msgQueueSemId queueSemId;
|
||||||
msgQueueSemId queueSemId;
|
|
||||||
|
|
||||||
msgQueueReadSemIdIntern(queueSemId, externId, queueIdx);
|
msgQueueReadSemIdIntern(queueSemId,externId,queueIdx);
|
||||||
queueSemFd = sem_open(queueSemId, O_CREAT, SEM_DEFAULT_MODE, 1);
|
queueSemFd=sem_open(queueSemId,O_CREAT,SEM_DEFAULT_MODE,1);
|
||||||
if (queueSemFd == SEM_FAILED) {
|
if(queueSemFd==SEM_FAILED){
|
||||||
NZG_ERROR("sem_open", queueSemId);
|
NZG_ERROR("sem_open",queueSemId);
|
||||||
goto ERROR;
|
goto ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sem_trywait(queueSemFd) == -1) {
|
if(sem_trywait(queueSemFd)==-1){
|
||||||
NZG_ERROR("sem_wait", queueSemId);
|
NZG_ERROR("sem_wait",queueSemId);
|
||||||
goto ERROR;
|
goto ERROR;
|
||||||
}
|
}
|
||||||
if (DEBUG) {
|
if (DEBUG) { printf("Locking %s\n",queueSemId); }
|
||||||
printf("Locking %s\n", queueSemId);
|
semval=0;
|
||||||
}
|
sem_getvalue(queueSemFd,&semval);
|
||||||
semval = 0;
|
if (DEBUG) { printf("(AfterValue:%d)\n",semval); }
|
||||||
sem_getvalue(queueSemFd, &semval);
|
|
||||||
if (DEBUG) {
|
|
||||||
printf("(AfterValue:%d)\n", semval);
|
|
||||||
}
|
|
||||||
|
|
||||||
sem_close(queueSemFd);
|
sem_close(queueSemFd);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
ERROR:
|
ERROR:
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,35 +3,32 @@
|
||||||
|
|
||||||
#define DEBUG 0
|
#define DEBUG 0
|
||||||
|
|
||||||
int msgQueueReadUnlock(msgSpaceId externId, int queueIdx)
|
int msgQueueReadUnlock(msgSpaceId externId,int queueIdx){
|
||||||
{
|
int semval;
|
||||||
int semval;
|
sem_t * queueSemFd;
|
||||||
sem_t *queueSemFd;
|
msgQueueSemId queueSemId;
|
||||||
msgQueueSemId queueSemId;
|
|
||||||
|
|
||||||
msgQueueReadSemIdIntern(queueSemId, externId, queueIdx);
|
msgQueueReadSemIdIntern(queueSemId,externId,queueIdx);
|
||||||
if (DEBUG) {
|
if (DEBUG) { printf("Unlocking %s\n",queueSemId); }
|
||||||
printf("Unlocking %s\n", queueSemId);
|
queueSemFd=sem_open(queueSemId,O_CREAT,SEM_DEFAULT_MODE,1);
|
||||||
}
|
if(queueSemFd==SEM_FAILED){
|
||||||
queueSemFd = sem_open(queueSemId, O_CREAT, SEM_DEFAULT_MODE, 1);
|
NZG_ERROR("sem_open",queueSemId);
|
||||||
if (queueSemFd == SEM_FAILED) {
|
goto ERROR;
|
||||||
NZG_ERROR("sem_open", queueSemId);
|
}
|
||||||
goto ERROR;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (sem_post(queueSemFd) == -1) {
|
if(sem_post(queueSemFd)==-1){
|
||||||
NZG_ERROR("sem_post", queueSemId);
|
NZG_ERROR("sem_post",queueSemId);
|
||||||
goto ERROR;
|
goto ERROR;
|
||||||
}
|
}
|
||||||
semval = 0;
|
semval=0;
|
||||||
sem_getvalue(queueSemFd, &semval);
|
sem_getvalue(queueSemFd,&semval);
|
||||||
if (DEBUG) {
|
if (DEBUG) { printf("(AfterValue:%d)\n",semval); }
|
||||||
printf("(AfterValue:%d)\n", semval);
|
|
||||||
}
|
|
||||||
|
|
||||||
sem_close(queueSemFd);
|
|
||||||
|
|
||||||
return 0;
|
sem_close(queueSemFd);
|
||||||
ERROR:
|
|
||||||
return -1;
|
return 0;
|
||||||
|
ERROR:
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,36 +2,37 @@
|
||||||
|
|
||||||
// l'id de l'element enlevé vas dans oldElemId
|
// l'id de l'element enlevé vas dans oldElemId
|
||||||
|
|
||||||
int msgQueueRem(msgQueue * queue, msgQueueElemId oldElemId)
|
int msgQueueRem(msgQueue * queue, msgQueueElemId oldElemId){
|
||||||
{
|
msgQueueElem * queueOldHeadElem;
|
||||||
msgQueueElem *queueOldHeadElem;
|
|
||||||
|
|
||||||
if (strcmp(queue->headId, queue->id) == 0) {
|
|
||||||
NZG_ERROR("msgQueueElemRem : Empty queue", queue->id);
|
if (strcmp(queue->headId,queue->id)==0){
|
||||||
goto ERROR;
|
NZG_ERROR("msgQueueElemRem : Empty queue",queue->id);
|
||||||
}
|
goto ERROR;
|
||||||
strcpy(oldElemId, queue->headId);
|
}
|
||||||
|
strcpy(oldElemId,queue->headId);
|
||||||
|
|
||||||
queueOldHeadElem = msgQueueElemOpen(oldElemId);
|
queueOldHeadElem=msgQueueElemOpen(oldElemId);
|
||||||
if (queueOldHeadElem == NULL) {
|
if (queueOldHeadElem == NULL){
|
||||||
NZG_ERROR("msgQueueElemOpen", oldElemId);
|
NZG_ERROR("msgQueueElemOpen",oldElemId);
|
||||||
goto ERROR;
|
goto ERROR;
|
||||||
}
|
}
|
||||||
// on indique à la queue le nouveau premier element
|
|
||||||
strcpy(queue->headId, queueOldHeadElem->next);
|
|
||||||
if (strcmp(queueOldHeadElem->next, oldElemId) == 0) {
|
|
||||||
strcpy(queue->headId, queue->id);
|
|
||||||
}
|
|
||||||
// on fait en sorte que l'element ne connaisse plus
|
|
||||||
// ses voisins (utile pour le Delete)
|
|
||||||
strcpy(queueOldHeadElem->next, queueOldHeadElem->id);
|
|
||||||
|
|
||||||
if (msgQueueElemClose(queueOldHeadElem) < 0) {
|
// on indique à la queue le nouveau premier element
|
||||||
NZG_ERROR("msgQueueElemClose", oldElemId);
|
strcpy(queue->headId,queueOldHeadElem->next);
|
||||||
goto ERROR;
|
if (strcmp(queueOldHeadElem->next,oldElemId)==0){
|
||||||
|
strcpy(queue->headId,queue->id);
|
||||||
|
}
|
||||||
|
// on fait en sorte que l'element ne connaisse plus
|
||||||
|
// ses voisins (utile pour le Delete)
|
||||||
|
strcpy(queueOldHeadElem->next,queueOldHeadElem->id);
|
||||||
|
|
||||||
}
|
if (msgQueueElemClose(queueOldHeadElem)<0 ){
|
||||||
return 0;
|
NZG_ERROR("msgQueueElemClose",oldElemId);
|
||||||
ERROR:
|
goto ERROR;
|
||||||
return -1;
|
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
ERROR:
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,16 +1,15 @@
|
||||||
#include "libnazgul.h"
|
#include "libnazgul.h"
|
||||||
|
|
||||||
int msgSpaceClose(msgSpace * space)
|
int msgSpaceClose(msgSpace * space){
|
||||||
{
|
msgSpaceId spaceId;
|
||||||
msgSpaceId spaceId;
|
strcpy(spaceId,space->id);
|
||||||
strcpy(spaceId, space->id);
|
|
||||||
|
|
||||||
if (munmap(space, sizeof(msgSpace)) < 0) {
|
if (munmap(space,sizeof(msgSpace)) < 0){
|
||||||
NZG_ERROR("unmap", spaceId);
|
NZG_ERROR("unmap",spaceId);
|
||||||
goto ERROR;
|
goto ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
ERROR:
|
ERROR:
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,10 +2,10 @@
|
||||||
#include "ids.h"
|
#include "ids.h"
|
||||||
|
|
||||||
/* prototypes des fonctions annexes à ne pas exporter */
|
/* prototypes des fonctions annexes à ne pas exporter */
|
||||||
int msgSpaceIdIntern(msgSpaceId dest, const msgSpaceId src);
|
int msgSpaceIdIntern(msgSpaceId dest,const msgSpaceId src );
|
||||||
int msgPoolDataIdIntern(msgSpaceId dest, const msgSpaceId src);
|
int msgPoolDataIdIntern(msgSpaceId dest,const msgSpaceId src );
|
||||||
int msgPoolDataTabSemIdIntern(msgPoolSemId destSemId,
|
int msgPoolDataTabSemIdIntern(
|
||||||
const msgSpaceId externId);
|
msgPoolSemId destSemId,const msgSpaceId externId);
|
||||||
/*
|
/*
|
||||||
* spaceId : identifiant externe de l'espace de msg
|
* spaceId : identifiant externe de l'espace de msg
|
||||||
* queueNb : nombre de files de messages
|
* queueNb : nombre de files de messages
|
||||||
|
@ -13,185 +13,185 @@ int msgPoolDataTabSemIdIntern(msgPoolSemId destSemId,
|
||||||
* queueNbCar : tableau de caracteristiques des different pool
|
* queueNbCar : tableau de caracteristiques des different pool
|
||||||
*/
|
*/
|
||||||
|
|
||||||
msgSpace *msgSpaceCreate(msgSpaceId externId,
|
msgSpace * msgSpaceCreate(
|
||||||
int queueNb, int poolNb, msgPool * poolInfos)
|
msgSpaceId externId,
|
||||||
{
|
int queueNb,
|
||||||
msgSpaceId nzgId;
|
int poolNb,
|
||||||
/* msgSpaceList mSList; */
|
msgPool * poolInfos ){
|
||||||
int mSFd; // shm file descriptor
|
msgSpaceId nzgId;
|
||||||
int i;
|
/* msgSpaceList mSList; */
|
||||||
int err;
|
int mSFd; // shm file descriptor
|
||||||
static int mSIdNum = -1;
|
int i;
|
||||||
msgSpace *space;
|
int err;
|
||||||
msgSpaceListElemId listElemId;
|
static int mSIdNum=-1;
|
||||||
|
msgSpace * space;
|
||||||
|
msgSpaceListElemId listElemId;
|
||||||
|
|
||||||
msgPoolDataTabId poolDataTabId;
|
msgPoolDataTabId poolDataTabId;
|
||||||
msgPoolData *poolDataTabAddr;
|
msgPoolData * poolDataTabAddr;
|
||||||
msgBufferInfoTabId bufferInfoTabId;
|
msgBufferInfoTabId bufferInfoTabId;
|
||||||
msgPoolId poolId;
|
msgPoolId poolId;
|
||||||
sem_t *mSDataTabSemFd;
|
sem_t * mSDataTabSemFd;
|
||||||
|
|
||||||
mSIdNum++;
|
mSIdNum++;
|
||||||
space = NULL;
|
space=NULL;
|
||||||
/** recuperation de la liste des msgSpace **/
|
/** recuperation de la liste des msgSpace **/
|
||||||
/* (creation si elle n'existe pas */
|
/* (creation si elle n'existe pas */
|
||||||
|
|
||||||
/** on créee le nouvel element **/
|
/** on créee le nouvel element **/
|
||||||
printf("PAGESIZE : %d\n", (int)PAGESIZE);
|
printf("PAGESIZE : %d\n",(int)PAGESIZE);
|
||||||
if (msgSpaceIdIntern(nzgId, externId) < 0) {
|
if (msgSpaceIdIntern(nzgId,externId) < 0){
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (msgSpaceListInit() < 0) {
|
|
||||||
NZG_ERROR("msgSpaceListInit", nzgId);
|
|
||||||
goto ERROR;
|
|
||||||
};
|
|
||||||
if (msgSpaceListLock() < 0) {
|
|
||||||
NZG_ERROR("msgSpaceListLock", "");
|
|
||||||
goto ERROR;
|
|
||||||
}
|
|
||||||
if ((err = msgSpaceListFindId(externId)) < 1) {
|
|
||||||
if (err == 0) {
|
|
||||||
// soit le msgSpace existe deja
|
|
||||||
NZG_ERROR("spaceListFindId : existing ", nzgId);
|
|
||||||
} else {
|
|
||||||
// zut, il y a soit une erreur
|
|
||||||
NZG_ERROR("spaceListFindId : error ", nzgId);
|
|
||||||
}
|
|
||||||
msgSpaceListUnlock();
|
|
||||||
// on quitte
|
|
||||||
goto ERROR;
|
|
||||||
}
|
|
||||||
printf("spaceListFind ok\n");
|
|
||||||
if (msgSpaceListUnlock() < 0) {
|
|
||||||
NZG_ERROR("msgSpaceListUnlock", "");
|
|
||||||
goto ERROR;
|
|
||||||
}
|
|
||||||
printf("spaceListUnlock ok\n");
|
|
||||||
|
|
||||||
fprintf(stderr, "Creating msgSpace with id : %s\n", nzgId);
|
|
||||||
mSFd = shm_open(nzgId,
|
|
||||||
O_RDWR | O_CREAT | O_EXCL | O_TRUNC,
|
|
||||||
MSGSPACE_DEFAULT_MODE);
|
|
||||||
if (mSFd == -1) {
|
|
||||||
NZG_ERROR("shm_open : msgSpace creation", nzgId);
|
|
||||||
goto ERROR;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* on redimentionne l'element */
|
|
||||||
if (ftruncate(mSFd, sizeof(*space)) == -1) {
|
|
||||||
NZG_ERROR("ftruncate", nzgId);
|
|
||||||
goto ERROR;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Map the memory object */
|
|
||||||
space = mmap(0, sizeof(*space),
|
|
||||||
PROT_READ | PROT_WRITE, MAP_SHARED, mSFd, 0);
|
|
||||||
if (space == MAP_FAILED) {
|
|
||||||
NZG_ERROR("mmap", nzgId);
|
|
||||||
goto ERROR;
|
|
||||||
}
|
|
||||||
|
|
||||||
printf("CREAT: msgSpace mapped to 0x%08lx in %d\n", (long)space,
|
|
||||||
(int)getpid());
|
|
||||||
|
|
||||||
/* on ferme le descripteur du fichier */
|
|
||||||
close(mSFd);
|
|
||||||
|
|
||||||
/* on remplit la structure */
|
|
||||||
strcpy(space->id, nzgId);
|
|
||||||
space->poolNb = poolNb;
|
|
||||||
space->queueNb = queueNb;
|
|
||||||
space->pid = getpid();
|
|
||||||
msgPoolDataTabSemIdIntern(space->poolDataTabSemId, externId);
|
|
||||||
/* creation du poolData */
|
|
||||||
msgPoolDataIdIntern(poolDataTabId, externId);
|
|
||||||
strcpy(space->poolDataTabId, poolDataTabId);
|
|
||||||
strcpy(space->externId, externId);
|
|
||||||
|
|
||||||
mSDataTabSemFd = sem_open(space->poolDataTabSemId,
|
|
||||||
O_CREAT | O_EXCL, SEM_DEFAULT_MODE, 0);
|
|
||||||
if (mSDataTabSemFd == SEM_FAILED) {
|
|
||||||
NZG_ERROR("sem_open : creation de la ressource",
|
|
||||||
space->poolDataTabSemId);
|
|
||||||
goto ERROR;
|
|
||||||
} else {
|
|
||||||
/* NZG_ERROR("sem_open : creation oki",
|
|
||||||
space->poolDataTabSemId); */
|
|
||||||
}
|
|
||||||
sem_close(mSDataTabSemFd);
|
|
||||||
|
|
||||||
/* attacher le tableau des msgPoolData */
|
|
||||||
poolDataTabAddr = msgPoolDataTabCreate(space);
|
|
||||||
if (poolDataTabAddr == NULL) {
|
|
||||||
NZG_ERROR("msgPoolDataTabCreate", space->poolDataTabId);
|
|
||||||
goto ERROR;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (i = 0; i < poolNb; i++) {
|
|
||||||
/* Pour chacun des poolData
|
|
||||||
* - y écrire les informations passées en param
|
|
||||||
* - creer les zones mémoires de chacune des pool
|
|
||||||
*/
|
|
||||||
// creation d'une pool
|
|
||||||
poolDataTabAddr[i].bufferNb = poolInfos[i].bufferNb;
|
|
||||||
poolDataTabAddr[i].bufferSize = poolInfos[i].bufferSize;
|
|
||||||
poolDataTabAddr[i].allocDispBuffer = 0;
|
|
||||||
|
|
||||||
if (msgBufferInfoTabIdIntern(bufferInfoTabId, externId, i) ==
|
|
||||||
-1) {
|
|
||||||
fprintf(stderr,
|
|
||||||
"msgBufferInfoTabId creation failed for id %s\n",
|
|
||||||
(char *)poolId);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
strcpy(poolDataTabAddr[i].bufferInfoTabId, bufferInfoTabId);
|
|
||||||
printf("buffIfoTab %d name : %s\n", i,
|
|
||||||
poolDataTabAddr[i].bufferInfoTabId);
|
|
||||||
msgBufferInfoTabCreate(externId, poolDataTabAddr, i,
|
|
||||||
poolInfos[i].bufferNb);
|
|
||||||
|
|
||||||
if (msgPoolIdIntern(poolId, externId, i) == -1) {
|
|
||||||
fprintf(stderr, "msgPoolId creation failed for id %s\n",
|
|
||||||
(char *)poolId);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
strcpy(poolDataTabAddr[i].poolId, poolId);
|
|
||||||
msgPoolCreate(externId, i, poolInfos[i].bufferNb,
|
|
||||||
poolInfos[i].bufferSize);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/* on crée queueNb files de messages */
|
|
||||||
printf("Creating queues:\n");
|
|
||||||
for (i = 0; i < queueNb; i++) {
|
|
||||||
printf("- queue %i...", i);
|
|
||||||
fflush(stdout);
|
|
||||||
if (msgQueueInit(space->externId, i) < 0) {
|
|
||||||
printf("fail.\n");
|
|
||||||
NZG_ERROR("msgQueueInit : queue ?? for",
|
|
||||||
space->externId);
|
|
||||||
goto ERROR;
|
|
||||||
}
|
|
||||||
printf("ok.\n");
|
|
||||||
}
|
|
||||||
msgPoolDataTabClose(space, poolDataTabAddr);
|
|
||||||
/* on ajoute spaceId a la liste des msgSpace connus */
|
|
||||||
printf("spaceListInit...\n");
|
|
||||||
|
|
||||||
printf("ok\n");
|
|
||||||
msgSpaceListLock();
|
|
||||||
printf("spaceListLock...ok\n");
|
|
||||||
msgSpaceListElemCreate(listElemId, space);
|
|
||||||
printf("spaceListElemCreate...ok\n");
|
|
||||||
msgSpaceListAdd(listElemId);
|
|
||||||
printf("spaceListAdd...ok\n");
|
|
||||||
msgSpaceListUnlock();
|
|
||||||
printf("spaceListUnlock...ok\n");
|
|
||||||
|
|
||||||
/* on renvoie un pointeur sur le bon spaceId */
|
|
||||||
msgPoolDataTabUnlock(space);
|
|
||||||
return space;
|
|
||||||
ERROR:
|
|
||||||
return NULL;
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (msgSpaceListInit() <0){
|
||||||
|
NZG_ERROR("msgSpaceListInit",nzgId);
|
||||||
|
goto ERROR;
|
||||||
|
};
|
||||||
|
if (msgSpaceListLock() <0){
|
||||||
|
NZG_ERROR("msgSpaceListLock","");
|
||||||
|
goto ERROR;
|
||||||
|
}
|
||||||
|
if ((err=msgSpaceListFindId(externId)) < 1){
|
||||||
|
if (err==0){
|
||||||
|
// soit le msgSpace existe deja
|
||||||
|
NZG_ERROR("spaceListFindId : existing ",nzgId);
|
||||||
|
} else {
|
||||||
|
// zut, il y a soit une erreur
|
||||||
|
NZG_ERROR("spaceListFindId : error ",nzgId);
|
||||||
|
}
|
||||||
|
msgSpaceListUnlock();
|
||||||
|
// on quitte
|
||||||
|
goto ERROR;
|
||||||
|
}
|
||||||
|
printf("spaceListFind ok\n");
|
||||||
|
if (msgSpaceListUnlock() < 0){
|
||||||
|
NZG_ERROR("msgSpaceListUnlock","");
|
||||||
|
goto ERROR;
|
||||||
|
}
|
||||||
|
printf("spaceListUnlock ok\n");
|
||||||
|
|
||||||
|
fprintf(stderr,"Creating msgSpace with id : %s\n",nzgId);
|
||||||
|
mSFd=shm_open(
|
||||||
|
nzgId,
|
||||||
|
O_RDWR|O_CREAT|O_EXCL|O_TRUNC,
|
||||||
|
MSGSPACE_DEFAULT_MODE
|
||||||
|
);
|
||||||
|
if (mSFd == -1 ) {
|
||||||
|
NZG_ERROR("shm_open : msgSpace creation",nzgId);
|
||||||
|
goto ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* on redimentionne l'element */
|
||||||
|
if (ftruncate(mSFd, sizeof(* space)) == -1){
|
||||||
|
NZG_ERROR("ftruncate",nzgId);
|
||||||
|
goto ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Map the memory object */
|
||||||
|
space = mmap( 0, sizeof( *space ),
|
||||||
|
PROT_READ | PROT_WRITE,
|
||||||
|
MAP_SHARED, mSFd, 0 );
|
||||||
|
if( space == MAP_FAILED ) {
|
||||||
|
NZG_ERROR("mmap",nzgId);
|
||||||
|
goto ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
printf( "CREAT: msgSpace mapped to 0x%08x in %d\n", (int)space,(int)getpid());
|
||||||
|
|
||||||
|
/* on ferme le descripteur du fichier */
|
||||||
|
close(mSFd);
|
||||||
|
|
||||||
|
/* on remplit la structure */
|
||||||
|
strcpy(space->id,nzgId);
|
||||||
|
space->poolNb=poolNb;
|
||||||
|
space->queueNb=queueNb;
|
||||||
|
space->pid=getpid();
|
||||||
|
msgPoolDataTabSemIdIntern(space->poolDataTabSemId,externId);
|
||||||
|
/* creation du poolData */
|
||||||
|
msgPoolDataIdIntern(poolDataTabId,externId);
|
||||||
|
strcpy(space->poolDataTabId,poolDataTabId);
|
||||||
|
strcpy(space->externId,externId);
|
||||||
|
|
||||||
|
mSDataTabSemFd=sem_open(space->poolDataTabSemId,
|
||||||
|
O_CREAT|O_EXCL,SEM_DEFAULT_MODE,0);
|
||||||
|
if (mSDataTabSemFd == SEM_FAILED){
|
||||||
|
NZG_ERROR("sem_open : creation de la ressource",
|
||||||
|
space->poolDataTabSemId);
|
||||||
|
goto ERROR;
|
||||||
|
} else {
|
||||||
|
/* NZG_ERROR("sem_open : creation oki",
|
||||||
|
space->poolDataTabSemId); */
|
||||||
|
}
|
||||||
|
sem_close(mSDataTabSemFd);
|
||||||
|
|
||||||
|
/* attacher le tableau des msgPoolData */
|
||||||
|
poolDataTabAddr=msgPoolDataTabCreate(space);
|
||||||
|
if (poolDataTabAddr == NULL){
|
||||||
|
NZG_ERROR("msgPoolDataTabCreate",space->poolDataTabId);
|
||||||
|
goto ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (i=0;i<poolNb;i++){
|
||||||
|
/* Pour chacun des poolData
|
||||||
|
* - y écrire les informations passées en param
|
||||||
|
* - creer les zones mémoires de chacune des pool
|
||||||
|
*/
|
||||||
|
// creation d'une pool
|
||||||
|
poolDataTabAddr[i].bufferNb=poolInfos[i].bufferNb;
|
||||||
|
poolDataTabAddr[i].bufferSize=poolInfos[i].bufferSize;
|
||||||
|
poolDataTabAddr[i].allocDispBuffer=0;
|
||||||
|
|
||||||
|
if (msgBufferInfoTabIdIntern(bufferInfoTabId,externId,i) == -1){
|
||||||
|
fprintf( stderr, "msgBufferInfoTabId creation failed for id %s\n",
|
||||||
|
(char*)poolId );
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
strcpy(poolDataTabAddr[i].bufferInfoTabId,bufferInfoTabId);
|
||||||
|
printf("buffIfoTab %d name : %s\n",i,poolDataTabAddr[i].bufferInfoTabId);
|
||||||
|
msgBufferInfoTabCreate(externId,poolDataTabAddr,i,poolInfos[i].bufferNb);
|
||||||
|
|
||||||
|
if (msgPoolIdIntern(poolId,externId,i) == -1){
|
||||||
|
fprintf( stderr, "msgPoolId creation failed for id %s\n",
|
||||||
|
(char*)poolId );
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
strcpy(poolDataTabAddr[i].poolId,poolId);
|
||||||
|
msgPoolCreate(externId,i,poolInfos[i].bufferNb,poolInfos[i].bufferSize);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/* on crée queueNb files de messages */
|
||||||
|
printf("Creating queues:\n");
|
||||||
|
for (i=0; i<queueNb;i++){
|
||||||
|
printf("- queue %i...",i); fflush(stdout);
|
||||||
|
if (msgQueueInit(space->externId,i) < 0){
|
||||||
|
printf("fail.\n");
|
||||||
|
NZG_ERROR("msgQueueInit : queue ?? for",space->externId);
|
||||||
|
goto ERROR;
|
||||||
|
}
|
||||||
|
printf("ok.\n");
|
||||||
|
}
|
||||||
|
msgPoolDataTabClose(space,poolDataTabAddr);
|
||||||
|
/* on ajoute spaceId a la liste des msgSpace connus */
|
||||||
|
printf("spaceListInit...\n");
|
||||||
|
|
||||||
|
printf("ok\n");
|
||||||
|
msgSpaceListLock();
|
||||||
|
printf("spaceListLock...ok\n");
|
||||||
|
msgSpaceListElemCreate(listElemId,space);
|
||||||
|
printf("spaceListElemCreate...ok\n");
|
||||||
|
msgSpaceListAdd(listElemId);
|
||||||
|
printf("spaceListAdd...ok\n");
|
||||||
|
msgSpaceListUnlock();
|
||||||
|
printf("spaceListUnlock...ok\n");
|
||||||
|
|
||||||
|
/* on renvoie un pointeur sur le bon spaceId */
|
||||||
|
msgPoolDataTabUnlock(space);
|
||||||
|
return space;
|
||||||
|
ERROR:
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -2,66 +2,66 @@
|
||||||
#include "ids.h"
|
#include "ids.h"
|
||||||
|
|
||||||
/* prototypes des fonctions annexes à ne pas exporter */
|
/* prototypes des fonctions annexes à ne pas exporter */
|
||||||
int msgSpaceIdIntern(msgSpaceId dest, const msgSpaceId src);
|
int msgSpaceIdIntern(msgSpaceId dest,const msgSpaceId src );
|
||||||
int msgPoolDataIdIntern(msgSpaceId dest, const msgSpaceId src);
|
int msgPoolDataIdIntern(msgSpaceId dest,const msgSpaceId src );
|
||||||
int msgPoolDataTabSemIdIntern(msgPoolSemId destSemId,
|
int msgPoolDataTabSemIdIntern(
|
||||||
const msgSpaceId externId);
|
msgPoolSemId destSemId,const msgSpaceId externId);
|
||||||
|
|
||||||
int msgSpaceDelete(msgSpaceId externId)
|
int msgSpaceDelete(msgSpaceId externId){
|
||||||
{
|
//int shmId;
|
||||||
//int shmId;
|
msgSpaceId nzgId;
|
||||||
msgSpaceId nzgId;
|
msgSpace * space;
|
||||||
msgSpace *space;
|
int i;
|
||||||
int i;
|
fprintf(stderr,"Deleting msgSpace with id : %s\n",externId);
|
||||||
fprintf(stderr, "Deleting msgSpace with id : %s\n", externId);
|
if (msgSpaceIdIntern(nzgId,externId) == -1){
|
||||||
if (msgSpaceIdIntern(nzgId, externId) == -1) {
|
NZG_ERROR("msgSpaceIdIntern",externId);
|
||||||
NZG_ERROR("msgSpaceIdIntern", externId);
|
goto ERROR;
|
||||||
goto ERROR;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
space = msgSpaceOpen(externId);
|
space = msgSpaceOpen(externId);
|
||||||
/* supprimer chaque pool */
|
/* supprimer chaque pool */
|
||||||
for (i = 0; i < space->poolNb; i++) {
|
for (i=0;i<space->poolNb;i++){
|
||||||
msgPoolDelete(externId, i);
|
msgPoolDelete(externId,i);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* supprimer chaque queue */
|
/* supprimer chaque queue */
|
||||||
for (i = 0; i < space->queueNb; i++) {
|
for (i=0;i<space->queueNb;i++){
|
||||||
msgQueueDelete(externId, i);
|
msgQueueDelete(externId,i);
|
||||||
}
|
}
|
||||||
printf("openned successfully !\n");
|
printf("openned successfully !\n");
|
||||||
printf("Unlinking DataTab... ");
|
printf("Unlinking DataTab... ");
|
||||||
if (shm_unlink(space->poolDataTabId) < 0) {
|
if (shm_unlink(space->poolDataTabId) < 0){
|
||||||
perror("shm_unlink");
|
perror("shm_unlink");
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
printf("ok\n");
|
|
||||||
|
|
||||||
printf("Unlinking DataTabSem... ");
|
|
||||||
if (sem_unlink(space->poolDataTabSemId) < 0) {
|
|
||||||
NZG_ERROR("sem_unlink", space->poolDataTabSemId);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
printf("ok\n");
|
|
||||||
|
|
||||||
if (shm_unlink(nzgId) < 0) {
|
|
||||||
NZG_ERROR("shm_unlink", nzgId);
|
|
||||||
goto ERROR;
|
|
||||||
};
|
|
||||||
if (msgSpaceListLock() < 0) {
|
|
||||||
NZG_ERROR("msgSpaceListLock", "");
|
|
||||||
goto ERROR;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (msgSpaceListRem(nzgId) < 0) {
|
|
||||||
NZG_ERROR("msgSpaceListRem", nzgId);
|
|
||||||
goto ERROR;
|
|
||||||
}
|
|
||||||
if (msgSpaceListUnlock() < 0) {
|
|
||||||
NZG_ERROR("msgSpaceListUnlock", "");
|
|
||||||
goto ERROR;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
ERROR:
|
|
||||||
return -1;
|
return -1;
|
||||||
|
}
|
||||||
|
printf("ok\n");
|
||||||
|
|
||||||
|
printf("Unlinking DataTabSem... ");
|
||||||
|
if (sem_unlink(space->poolDataTabSemId) < 0){
|
||||||
|
NZG_ERROR("sem_unlink",space->poolDataTabSemId);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
printf("ok\n");
|
||||||
|
|
||||||
|
if (shm_unlink(nzgId)<0){
|
||||||
|
NZG_ERROR("shm_unlink",nzgId);
|
||||||
|
goto ERROR;
|
||||||
|
};
|
||||||
|
if (msgSpaceListLock()<0){
|
||||||
|
NZG_ERROR("msgSpaceListLock","");
|
||||||
|
goto ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (msgSpaceListRem(nzgId) < 0){
|
||||||
|
NZG_ERROR("msgSpaceListRem",nzgId);
|
||||||
|
goto ERROR;
|
||||||
|
}
|
||||||
|
if (msgSpaceListUnlock()< 0){
|
||||||
|
NZG_ERROR("msgSpaceListUnlock","");
|
||||||
|
goto ERROR;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
ERROR:
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,55 +3,54 @@
|
||||||
// ajoute un element en début de liste.
|
// ajoute un element en début de liste.
|
||||||
// fait pointer l'ancien dernier vers lui
|
// fait pointer l'ancien dernier vers lui
|
||||||
// il s'enregistre en tant que dernier chez la liste
|
// il s'enregistre en tant que dernier chez la liste
|
||||||
int msgSpaceListAdd(msgSpaceListElemId newElemId)
|
int msgSpaceListAdd(msgSpaceListElemId newElemId){
|
||||||
{
|
msgSpaceListElem * listOldTailElem;
|
||||||
msgSpaceListElem *listOldTailElem;
|
msgSpaceListElem * listNewTailElem;
|
||||||
msgSpaceListElem *listNewTailElem;
|
msgSpaceList * list;
|
||||||
msgSpaceList *list;
|
|
||||||
|
|
||||||
list = msgSpaceListOpen();
|
list=msgSpaceListOpen();
|
||||||
if (list == NULL) {
|
if (list == NULL){
|
||||||
NZG_ERROR("msgSpaceListOpen", "");
|
NZG_ERROR("msgSpaceListOpen","");
|
||||||
goto ERROR;
|
goto ERROR;
|
||||||
}
|
}
|
||||||
// on informe l'element qui est le dernier
|
// on informe l'element qui est le dernier
|
||||||
listNewTailElem = msgSpaceListElemOpen(newElemId);
|
listNewTailElem=msgSpaceListElemOpen(newElemId);
|
||||||
if (listNewTailElem == NULL) {
|
if (listNewTailElem==NULL){
|
||||||
NZG_ERROR("msgSpaceListElemOpen", newElemId);
|
NZG_ERROR("msgSpaceListElemOpen",newElemId);
|
||||||
goto ERROR;
|
goto ERROR;
|
||||||
}
|
|
||||||
strcpy(listNewTailElem->next, newElemId);
|
|
||||||
if (msgSpaceListElemClose(listNewTailElem) < 0) {
|
|
||||||
NZG_ERROR("msgSpaceListElemClose", newElemId);
|
|
||||||
goto ERROR;
|
|
||||||
}
|
}
|
||||||
|
strcpy(listNewTailElem->next,newElemId);
|
||||||
|
if (msgSpaceListElemClose(listNewTailElem) <0 ){
|
||||||
|
NZG_ERROR("msgSpaceListElemClose",newElemId);
|
||||||
|
goto ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
/* verifier si la liste n'est pas vide... */
|
/* verifier si la liste n'est pas vide... */
|
||||||
if ((strcmp(list->headId, list->id) == 0)
|
if((strcmp(list->headId,list->id)==0)
|
||||||
&& (strcmp(list->tailId, list->id) == 0)) {
|
&& (strcmp(list->tailId,list->id)==0)) {
|
||||||
printf("- premier elem de spaceList -\n");
|
printf("- premier elem de spaceList -\n");
|
||||||
// on donne a la queue l'id de l'element
|
// on donne a la queue l'id de l'element
|
||||||
strcpy(list->headId, newElemId);
|
strcpy(list->headId,newElemId);
|
||||||
strcpy(list->tailId, newElemId);
|
strcpy(list->tailId,newElemId);
|
||||||
} else {
|
} else {
|
||||||
/* on informe son prédecesseur qu'il a un suivant */
|
/* on informe son prédecesseur qu'il a un suivant */
|
||||||
listOldTailElem = msgSpaceListElemOpen(list->tailId);
|
listOldTailElem=msgSpaceListElemOpen(list->tailId);
|
||||||
if (listOldTailElem == NULL) {
|
if (listOldTailElem == NULL){
|
||||||
NZG_ERROR("msgSpaceListElemOpen", list->tailId);
|
NZG_ERROR("msgSpaceListElemOpen",list->tailId);
|
||||||
goto ERROR;
|
goto ERROR;
|
||||||
}
|
}
|
||||||
strcpy(listOldTailElem->next, newElemId);
|
strcpy(listOldTailElem->next,newElemId);
|
||||||
if (msgSpaceListElemClose(listOldTailElem) < 0) {
|
if (msgSpaceListElemClose(listOldTailElem) < 0){
|
||||||
NZG_ERROR("msgSpaceListElemClose", list->tailId);
|
NZG_ERROR("msgSpaceListElemClose",list->tailId);
|
||||||
goto ERROR;
|
goto ERROR;
|
||||||
}
|
}
|
||||||
// on donne a la queue l'id du dernier element
|
// on donne a la queue l'id du dernier element
|
||||||
strcpy(list->tailId, newElemId);
|
strcpy(list->tailId,newElemId);
|
||||||
}
|
}
|
||||||
// on incremente elemCounter
|
// on incremente elemCounter
|
||||||
msgSpaceListClose(list);
|
msgSpaceListClose(list);
|
||||||
return 0;
|
return 0;
|
||||||
ERROR:
|
ERROR:
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,18 +1,17 @@
|
||||||
#include "libnazgul.h"
|
#include "libnazgul.h"
|
||||||
#include "ids.h"
|
#include "ids.h"
|
||||||
|
|
||||||
int msgSpaceListClose(msgSpaceList * list)
|
int msgSpaceListClose(msgSpaceList * list){
|
||||||
{
|
|
||||||
|
msgSpaceListId spaceListId;
|
||||||
|
strcpy(spaceListId,DEFAULT_MSGSPACELISTID);
|
||||||
|
|
||||||
msgSpaceListId spaceListId;
|
if (munmap(list,sizeof(msgSpaceList)) < 0){
|
||||||
strcpy(spaceListId, DEFAULT_MSGSPACELISTID);
|
NZG_ERROR("unmap",spaceListId);
|
||||||
|
goto ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
if (munmap(list, sizeof(msgSpaceList)) < 0) {
|
return 0;
|
||||||
NZG_ERROR("unmap", spaceListId);
|
ERROR:
|
||||||
goto ERROR;
|
return -1;
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
ERROR:
|
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,15 +4,15 @@
|
||||||
int msgSpaceListElemClose(msgSpaceListElem * listElem)
|
int msgSpaceListElemClose(msgSpaceListElem * listElem)
|
||||||
{
|
{
|
||||||
|
|
||||||
msgSpaceListElemId eId;
|
msgSpaceListElemId eId;
|
||||||
strcpy(eId, listElem->id);
|
strcpy(eId,listElem->id);
|
||||||
|
|
||||||
if (munmap(listElem, sizeof(msgSpaceListElem)) < 0) {
|
if (munmap(listElem,sizeof(msgSpaceListElem)) < 0){
|
||||||
NZG_ERROR("unmap", eId);
|
NZG_ERROR("unmap",eId);
|
||||||
goto ERROR;
|
goto ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
ERROR:
|
ERROR:
|
||||||
return -1;
|
return-1;
|
||||||
};
|
};
|
||||||
|
|
|
@ -2,43 +2,47 @@
|
||||||
#include "ids.h"
|
#include "ids.h"
|
||||||
|
|
||||||
// cree un nouvel elemen
|
// cree un nouvel elemen
|
||||||
int msgSpaceListElemCreate(msgSpaceListElemId listElemId, msgSpace * space)
|
int msgSpaceListElemCreate(
|
||||||
|
msgSpaceListElemId listElemId,
|
||||||
|
msgSpace * space)
|
||||||
{
|
{
|
||||||
|
|
||||||
int listElemFd;
|
int listElemFd;
|
||||||
msgSpaceListElem *listElem;
|
msgSpaceListElem * listElem;
|
||||||
msgSpaceListElemIdIntern(listElemId, space->externId);
|
msgSpaceListElemIdIntern(listElemId,space->externId);
|
||||||
|
|
||||||
listElemFd = shm_open(listElemId,
|
listElemFd=shm_open(listElemId,
|
||||||
O_RDWR | O_CREAT | O_EXCL | O_TRUNC,
|
O_RDWR|O_CREAT|O_EXCL|O_TRUNC,
|
||||||
SHM_DEFAULT_MODE);
|
SHM_DEFAULT_MODE);
|
||||||
|
|
||||||
if (listElemFd == -1) {
|
if (listElemFd == -1 ) {
|
||||||
NZG_ERROR("shm_open : msgSpaceListElem creation", listElemId);
|
NZG_ERROR("shm_open : msgSpaceListElem creation",listElemId);
|
||||||
goto ERROR;
|
goto ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ftruncate(listElemFd, sizeof(msgSpaceListElem)) < 0) {
|
if (ftruncate(listElemFd, sizeof(msgSpaceListElem)) < 0){
|
||||||
NZG_ERROR("ftruncate", listElemId);
|
NZG_ERROR("ftruncate", listElemId);
|
||||||
goto ERROR;
|
goto ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
close(listElemFd);
|
close(listElemFd);
|
||||||
listElem = msgSpaceListElemOpen(listElemId);
|
listElem=msgSpaceListElemOpen(listElemId);
|
||||||
if (listElem == NULL) {
|
if (listElem ==NULL){
|
||||||
NZG_ERROR("msgSpaceListElemOpen", listElemId);
|
NZG_ERROR("msgSpaceListElemOpen",listElemId);
|
||||||
goto ERROR;
|
goto ERROR;
|
||||||
}
|
}
|
||||||
strcpy(listElem->id, listElemId);
|
strcpy(listElem->id,listElemId);
|
||||||
strcpy(listElem->next, listElemId);
|
strcpy(listElem->next,listElemId);
|
||||||
strcpy(listElem->spaceId, space->id);
|
strcpy(listElem->spaceId,space->id);
|
||||||
printf("[ ListElem : id %s,next: %s, Sid: %s ]\n",
|
printf("[ ListElem : id %s,next: %s, Sid: %s ]\n",
|
||||||
listElem->id, listElem->next, listElem->spaceId);
|
listElem->id,
|
||||||
if (msgSpaceListElemClose(listElem) < 0) {
|
listElem->next,
|
||||||
NZG_ERROR("msgSpaceListElemClose", listElemId);
|
listElem->spaceId);
|
||||||
}
|
if (msgSpaceListElemClose(listElem) <0){
|
||||||
return 0;
|
NZG_ERROR("msgSpaceListElemClose",listElemId);
|
||||||
ERROR:
|
}
|
||||||
return -1;
|
return 0;
|
||||||
|
ERROR:
|
||||||
|
return -1;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -2,5 +2,6 @@
|
||||||
|
|
||||||
// modifie l'element suivant de l'element choisi
|
// modifie l'element suivant de l'element choisi
|
||||||
// et le fait pointer sur un nouvel ID
|
// et le fait pointer sur un nouvel ID
|
||||||
int msgSpaceListElemLinkNext(msgSpaceListElemId current,
|
int msgSpaceListElemLinkNext(msgSpaceListElemId current,msgSpaceListElemId next);
|
||||||
msgSpaceListElemId next);
|
|
||||||
|
|
||||||
|
|
|
@ -2,29 +2,32 @@
|
||||||
#include "ids.h"
|
#include "ids.h"
|
||||||
|
|
||||||
// cree un nouvel elemen
|
// cree un nouvel elemen
|
||||||
void *msgSpaceListElemOpen(msgSpaceListElemId listElemId)
|
void * msgSpaceListElemOpen(msgSpaceListElemId listElemId){
|
||||||
{
|
int listElemFd;
|
||||||
int listElemFd;
|
void * listElemAddr;
|
||||||
void *listElemAddr;
|
|
||||||
|
|
||||||
listElemFd = shm_open(listElemId, O_RDWR, SHM_DEFAULT_MODE);
|
listElemFd=shm_open(listElemId,O_RDWR,SHM_DEFAULT_MODE);
|
||||||
if (listElemFd == -1) {
|
if (listElemFd == -1 ) {
|
||||||
NZG_ERROR("shm_open : msgSpaceListElem open", listElemId);
|
NZG_ERROR("shm_open : msgSpaceListElem open",listElemId);
|
||||||
goto ERROR;
|
goto ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
listElemAddr = mmap(NULL,
|
listElemAddr=mmap(NULL,
|
||||||
sizeof(msgQueueElem),
|
sizeof(msgQueueElem),
|
||||||
PROT_READ | PROT_WRITE, MAP_SHARED, listElemFd, 0);
|
PROT_READ|PROT_WRITE,
|
||||||
|
MAP_SHARED,
|
||||||
|
listElemFd,
|
||||||
|
0);
|
||||||
|
|
||||||
if (listElemAddr == MAP_FAILED) {
|
if( listElemAddr == MAP_FAILED ) {
|
||||||
NZG_ERROR("mmap", listElemId);
|
NZG_ERROR("mmap",listElemId);
|
||||||
goto ERROR;
|
goto ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
close(listElemFd);
|
||||||
|
return listElemAddr;
|
||||||
|
ERROR:
|
||||||
|
return NULL;
|
||||||
|
|
||||||
close(listElemFd);
|
|
||||||
return listElemAddr;
|
|
||||||
ERROR:
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -2,84 +2,78 @@
|
||||||
|
|
||||||
#define DEBUG 1
|
#define DEBUG 1
|
||||||
|
|
||||||
int msgSpaceListFindId(msgSpaceId externId)
|
int msgSpaceListFindId(msgSpaceId externId){
|
||||||
{
|
msgSpaceList * list;
|
||||||
msgSpaceList *list;
|
msgSpaceId spaceId;
|
||||||
msgSpaceId spaceId;
|
msgSpaceListElemId listHeadElemId;
|
||||||
msgSpaceListElemId listHeadElemId;
|
msgSpaceListElemId listTailElemId;
|
||||||
msgSpaceListElemId listTailElemId;
|
msgSpaceListId listId;
|
||||||
msgSpaceListId listId;
|
|
||||||
|
|
||||||
msgSpaceIdIntern(spaceId, externId);
|
msgSpaceIdIntern(spaceId,externId);
|
||||||
list = msgSpaceListOpen();
|
list=msgSpaceListOpen();
|
||||||
if (list == NULL) {
|
if (list==NULL){
|
||||||
NZG_ERROR("msgSpaceListOpen", "");
|
NZG_ERROR("msgSpaceListOpen","");
|
||||||
goto ERROR;
|
goto ERROR;
|
||||||
}
|
}
|
||||||
if (DEBUG) {
|
if (DEBUG) { printf("Before ListStrCpy\n"); }
|
||||||
printf("Before ListStrCpy\n");
|
strcpy(listHeadElemId,list->headId);
|
||||||
}
|
strcpy(listTailElemId,list->tailId);
|
||||||
strcpy(listHeadElemId, list->headId);
|
strcpy(listId,list->id);
|
||||||
strcpy(listTailElemId, list->tailId);
|
if (DEBUG) { printf("After ListStrCpy\n"); }
|
||||||
strcpy(listId, list->id);
|
if ((strcmp(listHeadElemId,listId)==0)
|
||||||
if (DEBUG) {
|
&& strcmp(listTailElemId,listId)==0){
|
||||||
printf("After ListStrCpy\n");
|
// si la liste est vide
|
||||||
}
|
if (DEBUG) { printf("SpaceList : vide\n"); }
|
||||||
if ((strcmp(listHeadElemId, listId) == 0)
|
return 1;
|
||||||
&& strcmp(listTailElemId, listId) == 0) {
|
} else {
|
||||||
// si la liste est vide
|
return msgSpaceListElemFindId(listHeadElemId,spaceId);
|
||||||
if (DEBUG) {
|
}
|
||||||
printf("SpaceList : vide\n");
|
if (msgSpaceListClose(list) < 0){
|
||||||
}
|
NZG_ERROR("msgSpaceListClose","");
|
||||||
return 1;
|
goto ERROR;
|
||||||
} else {
|
}
|
||||||
return msgSpaceListElemFindId(listHeadElemId, spaceId);
|
return 0;
|
||||||
}
|
ERROR:
|
||||||
if (msgSpaceListClose(list) < 0) {
|
return -1;
|
||||||
NZG_ERROR("msgSpaceListClose", "");
|
|
||||||
goto ERROR;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
ERROR:
|
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int msgSpaceListElemFindId(msgSpaceListElemId elemId, msgSpaceId spaceId)
|
int msgSpaceListElemFindId(msgSpaceListElemId elemId,msgSpaceId spaceId){
|
||||||
{
|
msgSpaceListElem * listElem;
|
||||||
msgSpaceListElem *listElem;
|
msgSpaceListElemId listElemIdNext;
|
||||||
msgSpaceListElemId listElemIdNext;
|
msgSpaceId currentElemSpaceId;
|
||||||
msgSpaceId currentElemSpaceId;
|
|
||||||
|
|
||||||
listElem = msgSpaceListElemOpen(elemId);
|
|
||||||
if (listElem == NULL) {
|
|
||||||
NZG_ERROR("msgSpaceListElemOpen", elemId);
|
|
||||||
goto ERROR;
|
|
||||||
}
|
|
||||||
strcpy(listElemIdNext, listElem->next);
|
|
||||||
strcpy(currentElemSpaceId, listElem->spaceId);
|
|
||||||
if (msgSpaceListElemClose(listElem) < 0) {
|
|
||||||
NZG_ERROR("msgSpaceListElemClose", elemId);
|
|
||||||
goto ERROR;
|
|
||||||
}
|
|
||||||
|
|
||||||
printf("Current ListElem: Next:%s, Sid:%s\n",
|
|
||||||
listElemIdNext, currentElemSpaceId);
|
|
||||||
printf("comparisons...\n");
|
|
||||||
if (strcmp(currentElemSpaceId, spaceId) == 0) {
|
|
||||||
printf("Found %s in spaceList !\n", spaceId);
|
|
||||||
return 0;
|
|
||||||
} else {
|
|
||||||
if (strcmp(listElemIdNext, elemId) == 0) {
|
|
||||||
printf("End of spaceList reached.\n");
|
|
||||||
/* fin de liste ?? */
|
|
||||||
return 1;
|
|
||||||
} else {
|
|
||||||
/* continuer sur l'element suivant */
|
|
||||||
return msgSpaceListElemFindId(listElemIdNext, spaceId);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
listElem=msgSpaceListElemOpen(elemId);
|
||||||
|
if (listElem==NULL){
|
||||||
|
NZG_ERROR("msgSpaceListElemOpen",elemId);
|
||||||
|
goto ERROR;
|
||||||
|
}
|
||||||
|
strcpy(listElemIdNext,listElem->next);
|
||||||
|
strcpy(currentElemSpaceId,listElem->spaceId);
|
||||||
|
if (msgSpaceListElemClose(listElem) < 0){
|
||||||
|
NZG_ERROR("msgSpaceListElemClose",elemId);
|
||||||
|
goto ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("Current ListElem: Next:%s, Sid:%s\n",
|
||||||
|
listElemIdNext,currentElemSpaceId);
|
||||||
|
printf("comparisons...\n");
|
||||||
|
if (strcmp(currentElemSpaceId,spaceId)==0) {
|
||||||
|
printf("Found %s in spaceList !\n",spaceId);
|
||||||
return 0;
|
return 0;
|
||||||
ERROR:
|
} else {
|
||||||
return -1;
|
if (strcmp(listElemIdNext,elemId)==0){
|
||||||
|
printf("End of spaceList reached.\n");
|
||||||
|
/* fin de liste ?? */
|
||||||
|
return 1;
|
||||||
|
} else {
|
||||||
|
/* continuer sur l'element suivant */
|
||||||
|
return msgSpaceListElemFindId(listElemIdNext,spaceId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
ERROR:
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,73 +1,76 @@
|
||||||
#include "libnazgul.h"
|
#include "libnazgul.h"
|
||||||
#include "ids.h"
|
#include "ids.h"
|
||||||
|
|
||||||
int msgSpaceListInit()
|
int msgSpaceListInit(){
|
||||||
{
|
int spaceListFd;
|
||||||
int spaceListFd;
|
sem_t * spaceListSemFd;
|
||||||
sem_t *spaceListSemFd;
|
msgSpaceList *list;
|
||||||
msgSpaceList *list;
|
|
||||||
|
|
||||||
msgSpaceListSemId spaceListSemId;
|
msgSpaceListSemId spaceListSemId;
|
||||||
msgSpaceListId spaceListId;
|
msgSpaceListId spaceListId;
|
||||||
|
|
||||||
strcpy(spaceListSemId, DEFAULT_MSGSPACELISTSEMID);
|
strcpy(spaceListSemId,DEFAULT_MSGSPACELISTSEMID);
|
||||||
strcpy(spaceListId, DEFAULT_MSGSPACELISTID);
|
strcpy(spaceListId,DEFAULT_MSGSPACELISTID);
|
||||||
|
|
||||||
/* Creation de semaphore */
|
/* Creation de semaphore */
|
||||||
spaceListSemFd = sem_open(spaceListSemId, O_CREAT | O_EXCL, 0666, 0);
|
spaceListSemFd=sem_open(spaceListSemId,O_CREAT|O_EXCL,0666,0);
|
||||||
if (spaceListSemFd == SEM_FAILED) {
|
if(spaceListSemFd==SEM_FAILED){
|
||||||
spaceListSemFd = sem_open(spaceListSemId, O_CREAT, 0666, 0);
|
spaceListSemFd=sem_open(spaceListSemId,O_CREAT,0666,0);
|
||||||
if (spaceListSemFd == SEM_FAILED) {
|
if(spaceListSemFd==SEM_FAILED){
|
||||||
NZG_ERROR("sem_open", spaceListSemId);
|
NZG_ERROR("sem_open",spaceListSemId);
|
||||||
goto ERROR;
|
goto ERROR;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*Fait un segment de memoir partager sur espace de listelement */
|
|
||||||
spaceListFd = shm_open(spaceListId,
|
|
||||||
O_RDWR | O_CREAT | O_EXCL | O_TRUNC, 0666);
|
|
||||||
if (spaceListFd == -1) {
|
|
||||||
spaceListFd = shm_open(spaceListId, O_RDWR, 0666);
|
|
||||||
if (spaceListFd == -1) {
|
|
||||||
NZG_ERROR("shm_open", spaceListId);
|
|
||||||
goto ERROR;
|
|
||||||
} else {
|
|
||||||
close(spaceListFd);
|
|
||||||
goto EXISTING;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (ftruncate(spaceListFd, sizeof(msgSpaceList)) < 0) {
|
|
||||||
NZG_ERROR("ftruncate", spaceListId);
|
|
||||||
goto ERROR;
|
|
||||||
}
|
|
||||||
close(spaceListFd);
|
|
||||||
|
|
||||||
list = msgSpaceListOpen();
|
|
||||||
if (list == NULL) {
|
|
||||||
NZG_ERROR("msgSpaceListOpen", "");
|
|
||||||
goto ERROR;
|
|
||||||
}
|
|
||||||
strcpy(list->id, spaceListId);
|
|
||||||
strcpy(list->headId, spaceListId);
|
|
||||||
strcpy(list->tailId, spaceListId);
|
|
||||||
if (msgSpaceListClose(list) < 0) {
|
|
||||||
NZG_ERROR("msgSpaceListClose", "");
|
|
||||||
goto ERROR;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (msgSpaceListUnlock() < 0) {
|
/*Fait un segment de memoir partager sur espace de listelement*/
|
||||||
NZG_ERROR("msgSpaceListUnlock", "");
|
spaceListFd=shm_open(spaceListId,
|
||||||
goto ERROR;
|
O_RDWR|O_CREAT|O_EXCL|O_TRUNC,
|
||||||
|
0666);
|
||||||
|
if (spaceListFd == -1){
|
||||||
|
spaceListFd=shm_open(spaceListId,O_RDWR,0666);
|
||||||
|
if (spaceListFd == -1){
|
||||||
|
NZG_ERROR("shm_open",spaceListId);
|
||||||
|
goto ERROR;
|
||||||
|
} else {
|
||||||
|
close(spaceListFd);
|
||||||
|
goto EXISTING;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
if (ftruncate(spaceListFd, sizeof(msgSpaceList)) < 0){
|
||||||
|
NZG_ERROR("ftruncate",spaceListId);
|
||||||
|
goto ERROR;
|
||||||
|
}
|
||||||
|
close(spaceListFd);
|
||||||
|
|
||||||
return 0;
|
list=msgSpaceListOpen();
|
||||||
ERROR:
|
if (list == NULL){
|
||||||
return -1;
|
NZG_ERROR("msgSpaceListOpen","");
|
||||||
EXISTING:
|
goto ERROR;
|
||||||
if (msgSpaceListUnlock() < 0) {
|
}
|
||||||
NZG_ERROR("msgSpaceListUnlock", "");
|
strcpy(list->id,spaceListId);
|
||||||
goto ERROR;
|
strcpy(list->headId,spaceListId);
|
||||||
}
|
strcpy(list->tailId,spaceListId);
|
||||||
|
if (msgSpaceListClose(list) <0){
|
||||||
|
NZG_ERROR("msgSpaceListClose","");
|
||||||
|
goto ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
if (msgSpaceListUnlock() < 0){
|
||||||
|
NZG_ERROR("msgSpaceListUnlock","");
|
||||||
|
goto ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
ERROR:
|
||||||
|
return -1;
|
||||||
|
EXISTING:
|
||||||
|
if (msgSpaceListUnlock() < 0){
|
||||||
|
NZG_ERROR("msgSpaceListUnlock","");
|
||||||
|
goto ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -1,65 +1,69 @@
|
||||||
#include "libnazgul.h"
|
#include "libnazgul.h"
|
||||||
|
|
||||||
|
|
||||||
// verouille le semaphore de la liste
|
// verouille le semaphore de la liste
|
||||||
|
|
||||||
int msgSpaceListLock()
|
int msgSpaceListLock(){
|
||||||
{
|
sem_t * msgSpaceListSemFd;
|
||||||
sem_t *msgSpaceListSemFd;
|
msgSpaceListSemId spaceListSemId;
|
||||||
msgSpaceListSemId spaceListSemId;
|
strcpy(spaceListSemId,DEFAULT_MSGSPACELISTSEMID);
|
||||||
strcpy(spaceListSemId, DEFAULT_MSGSPACELISTSEMID);
|
|
||||||
|
|
||||||
/* Ouverture d'un semafore */
|
/* Ouverture d'un semafore */
|
||||||
msgSpaceListSemFd = sem_open(spaceListSemId, O_CREAT, 0666, 1);
|
msgSpaceListSemFd=sem_open(spaceListSemId,O_CREAT,0666,1);
|
||||||
if (msgSpaceListSemFd == SEM_FAILED) {
|
if(msgSpaceListSemFd==SEM_FAILED){
|
||||||
NZG_ERROR("sem_open", spaceListSemId);
|
NZG_ERROR("sem_open",spaceListSemId);
|
||||||
goto ERROR;
|
goto ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Pose d'un semaphore et le verrouille */
|
/* Pose d'un semaphore et le verrouille */
|
||||||
if (sem_wait(msgSpaceListSemFd) == -1) {
|
if(sem_wait(msgSpaceListSemFd)==-1){
|
||||||
NZG_ERROR("sem_wait", spaceListSemId);
|
NZG_ERROR("sem_wait",spaceListSemId);
|
||||||
goto ERROR;
|
goto ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Ferme le semaphore */
|
/* Ferme le semaphore*/
|
||||||
/* if(sem_close(msgSpaceListSemFd)==-1){
|
/* if(sem_close(msgSpaceListSemFd)==-1){
|
||||||
NZG_ERROR("sem_close",spaceListSemId);
|
NZG_ERROR("sem_close",spaceListSemId);
|
||||||
return -1;
|
return -1;
|
||||||
} */
|
}*/
|
||||||
sem_close(msgSpaceListSemFd);
|
sem_close(msgSpaceListSemFd);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
ERROR:
|
ERROR:
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// deverouille le semaphore de la liste
|
// deverouille le semaphore de la liste
|
||||||
int msgSpaceListUnlock()
|
int msgSpaceListUnlock(){
|
||||||
{
|
sem_t * msgSpaceListSemFd;
|
||||||
sem_t *msgSpaceListSemFd;
|
msgSpaceListSemId spaceListSemId;
|
||||||
msgSpaceListSemId spaceListSemId;
|
strcpy(spaceListSemId,DEFAULT_MSGSPACELISTSEMID);
|
||||||
strcpy(spaceListSemId, DEFAULT_MSGSPACELISTSEMID);
|
|
||||||
|
|
||||||
/*Ouverture dun semaphore */
|
|
||||||
msgSpaceListSemFd = sem_open(spaceListSemId, O_CREAT, 0666, 0);
|
|
||||||
if (msgSpaceListSemFd == SEM_FAILED) {
|
|
||||||
NZG_ERROR("sem_open", spaceListSemId);
|
|
||||||
goto ERROR;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*Relachement du semaphore */
|
/*Ouverture dun semaphore*/
|
||||||
if (sem_post(msgSpaceListSemFd) == -1) {
|
msgSpaceListSemFd=sem_open(spaceListSemId,O_CREAT,0666,0);
|
||||||
NZG_ERROR("sem_relache", spaceListSemId);
|
if(msgSpaceListSemFd==SEM_FAILED){
|
||||||
goto ERROR;
|
NZG_ERROR("sem_open",spaceListSemId);
|
||||||
}
|
goto ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
/* Ferme le semaphore */
|
|
||||||
if (sem_close(msgSpaceListSemFd) == -1) {
|
|
||||||
NZG_ERROR("sem_close", spaceListSemId);
|
|
||||||
goto ERROR;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
/*Relachement du semaphore*/
|
||||||
ERROR:
|
if(sem_post(msgSpaceListSemFd)==-1){
|
||||||
return -1;
|
NZG_ERROR("sem_relache",spaceListSemId);
|
||||||
|
goto ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* Ferme le semaphore */
|
||||||
|
if(sem_close(msgSpaceListSemFd)==-1){
|
||||||
|
NZG_ERROR("sem_close",spaceListSemId);
|
||||||
|
goto ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
ERROR:
|
||||||
|
return -1;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -1,30 +1,32 @@
|
||||||
#include "libnazgul.h"
|
#include "libnazgul.h"
|
||||||
#include "ids.h"
|
#include "ids.h"
|
||||||
|
|
||||||
void *msgSpaceListOpen()
|
void * msgSpaceListOpen(){
|
||||||
{
|
int listFd;
|
||||||
int listFd;
|
void * listAddr;
|
||||||
void *listAddr;
|
|
||||||
|
|
||||||
msgSpaceListId spaceListId;
|
msgSpaceListId spaceListId;
|
||||||
strcpy(spaceListId, DEFAULT_MSGSPACELISTID);
|
strcpy(spaceListId,DEFAULT_MSGSPACELISTID);
|
||||||
|
|
||||||
listFd = shm_open(spaceListId, O_RDWR, SHM_DEFAULT_MODE);
|
listFd=shm_open(spaceListId,O_RDWR,SHM_DEFAULT_MODE);
|
||||||
if (listFd == -1) {
|
if (listFd == -1 ) {
|
||||||
NZG_ERROR("shm_open : msgSpaceList open", spaceListId);
|
NZG_ERROR("shm_open : msgSpaceList open",spaceListId);
|
||||||
goto ERROR;
|
goto ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
listAddr = mmap(NULL,
|
listAddr=mmap(NULL,
|
||||||
sizeof(msgSpaceList),
|
sizeof(msgSpaceList),
|
||||||
PROT_READ | PROT_WRITE, MAP_SHARED, listFd, 0);
|
PROT_READ|PROT_WRITE,
|
||||||
if (listAddr == MAP_FAILED) {
|
MAP_SHARED,
|
||||||
NZG_ERROR("mmap", spaceListId);
|
listFd,
|
||||||
goto ERROR;
|
0);
|
||||||
}
|
if( listAddr == MAP_FAILED ) {
|
||||||
|
NZG_ERROR("mmap",spaceListId);
|
||||||
|
goto ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
close(listFd);
|
close(listFd);
|
||||||
return listAddr;
|
return listAddr;
|
||||||
ERROR:
|
ERROR:
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,127 +2,109 @@
|
||||||
|
|
||||||
#define DEBUG 1
|
#define DEBUG 1
|
||||||
|
|
||||||
int msgSpaceListRem(msgSpaceId spaceId)
|
int msgSpaceListRem(msgSpaceId spaceId){
|
||||||
{
|
msgSpaceList * list;
|
||||||
msgSpaceList *list;
|
msgSpaceListElemId listHeadElemId;
|
||||||
msgSpaceListElemId listHeadElemId;
|
msgSpaceListElemId listTailElemId;
|
||||||
msgSpaceListElemId listTailElemId;
|
msgSpaceListId listId;
|
||||||
msgSpaceListId listId;
|
|
||||||
|
|
||||||
msgSpaceListElemId prevElemId;
|
msgSpaceListElemId prevElemId;
|
||||||
msgSpaceListElemId currElemId;
|
msgSpaceListElemId currElemId;
|
||||||
msgSpaceListElemId nextElemId;
|
msgSpaceListElemId nextElemId;
|
||||||
|
|
||||||
msgSpaceListElem *prevElem;
|
msgSpaceListElem * prevElem;
|
||||||
msgSpaceListElem *currElem;
|
msgSpaceListElem * currElem;
|
||||||
msgSpaceId currSpaceId;
|
msgSpaceId currSpaceId;
|
||||||
|
|
||||||
list = msgSpaceListOpen();
|
list=msgSpaceListOpen();
|
||||||
if (list == NULL) {
|
if (list==NULL){
|
||||||
NZG_ERROR("msgSpaceListOpen", "");
|
NZG_ERROR("msgSpaceListOpen","");
|
||||||
|
goto ERROR;
|
||||||
|
}
|
||||||
|
if (DEBUG) { printf("Before ListStrCpy\n"); }
|
||||||
|
strcpy(listHeadElemId,list->headId);
|
||||||
|
strcpy(listTailElemId,list->tailId);
|
||||||
|
strcpy(listId,list->id);
|
||||||
|
if (DEBUG) { printf("After ListStrCpy\n"); }
|
||||||
|
if ((strcmp(listHeadElemId,listId)==0)
|
||||||
|
&& strcmp(listTailElemId,listId)==0){
|
||||||
|
if (DEBUG) { printf("SpaceList : vide\n"); }
|
||||||
|
return 1;
|
||||||
|
} else {
|
||||||
|
bool found=false;
|
||||||
|
|
||||||
|
strcpy(prevElemId,list->headId);
|
||||||
|
strcpy(currElemId,list->headId);
|
||||||
|
while(!found){
|
||||||
|
printf("Recherche dans l'element %s\n",listHeadElemId);
|
||||||
|
currElem=msgSpaceListElemOpen(currElemId);
|
||||||
|
if (currElem==NULL){
|
||||||
|
NZG_ERROR("msgSpaceListElemOpen",currElemId);
|
||||||
goto ERROR;
|
goto ERROR;
|
||||||
}
|
}
|
||||||
if (DEBUG) {
|
strcpy(nextElemId,currElem->next);
|
||||||
printf("Before ListStrCpy\n");
|
strcpy(currSpaceId,currElem->spaceId);
|
||||||
}
|
if (msgSpaceListElemClose(currElem) <0){
|
||||||
strcpy(listHeadElemId, list->headId);
|
NZG_ERROR("msgSpaceListElemClose",currElemId);
|
||||||
strcpy(listTailElemId, list->tailId);
|
goto ERROR;
|
||||||
strcpy(listId, list->id);
|
}
|
||||||
if (DEBUG) {
|
if (strcmp(prevElemId,nextElemId)==0){
|
||||||
printf("After ListStrCpy\n");
|
// list à 1 seul élement
|
||||||
}
|
if (strcmp(currSpaceId,spaceId)==0){
|
||||||
if ((strcmp(listHeadElemId, listId) == 0)
|
// on a trouvé l'elem
|
||||||
&& strcmp(listTailElemId, listId) == 0) {
|
strcpy(list->headId,list->id);
|
||||||
if (DEBUG) {
|
strcpy(list->tailId,list->id);
|
||||||
printf("SpaceList : vide\n");
|
// on efface
|
||||||
|
shm_unlink(currElemId);
|
||||||
|
found=true;
|
||||||
|
} else {
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
return 1;
|
} else {
|
||||||
} else {
|
// liste à plusieurs élements...
|
||||||
bool found = false;
|
if (strcmp(currSpaceId,spaceId)==0){
|
||||||
|
// ca correspond
|
||||||
|
if (strcmp(prevElemId,currElemId)==0){
|
||||||
|
// si on est en début de liste (prev=current)
|
||||||
|
// - la tete de liste pointe sur le suivant
|
||||||
|
strcpy(list->headId,nextElemId);
|
||||||
|
} else {
|
||||||
|
if (strcmp(currElemId,nextElemId)==0){
|
||||||
|
// si on est en find de liste (current=next)
|
||||||
|
// - on fait pointer la queue de liste sur le précédent
|
||||||
|
strcpy(list->tailId,prevElemId);
|
||||||
|
// - on fait pointer le précédent sur lui-meme
|
||||||
|
prevElem=msgSpaceListElemOpen(prevElemId);
|
||||||
|
strcpy(prevElem->next,prevElemId);
|
||||||
|
msgSpaceListElemClose(prevElem);
|
||||||
|
}else {
|
||||||
|
// on est en milieu de liste
|
||||||
|
// - on fait pointer le précédent sur le suivant
|
||||||
|
prevElem=msgSpaceListElemOpen(prevElemId);
|
||||||
|
strcpy(prevElem->next,nextElemId);
|
||||||
|
msgSpaceListElemClose(prevElem);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// - on détruit l'actuel
|
||||||
|
shm_unlink(currElemId);
|
||||||
|
found=true;
|
||||||
|
break;
|
||||||
|
} else {
|
||||||
|
//cela ne correspond pas
|
||||||
|
//on recopie
|
||||||
|
strcpy(prevElemId,currElemId);
|
||||||
|
strcpy(currElemId,nextElemId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
strcpy(prevElemId, list->headId);
|
|
||||||
strcpy(currElemId, list->headId);
|
|
||||||
while (!found) {
|
|
||||||
printf("Recherche dans l'element %s\n", listHeadElemId);
|
|
||||||
currElem = msgSpaceListElemOpen(currElemId);
|
|
||||||
if (currElem == NULL) {
|
|
||||||
NZG_ERROR("msgSpaceListElemOpen", currElemId);
|
|
||||||
goto ERROR;
|
|
||||||
}
|
|
||||||
strcpy(nextElemId, currElem->next);
|
|
||||||
strcpy(currSpaceId, currElem->spaceId);
|
|
||||||
if (msgSpaceListElemClose(currElem) < 0) {
|
|
||||||
NZG_ERROR("msgSpaceListElemClose", currElemId);
|
|
||||||
goto ERROR;
|
|
||||||
}
|
|
||||||
if (strcmp(prevElemId, nextElemId) == 0) {
|
|
||||||
// list à 1 seul élement
|
|
||||||
if (strcmp(currSpaceId, spaceId) == 0) {
|
|
||||||
// on a trouvé l'elem
|
|
||||||
strcpy(list->headId, list->id);
|
|
||||||
strcpy(list->tailId, list->id);
|
|
||||||
// on efface
|
|
||||||
shm_unlink(currElemId);
|
|
||||||
found = true;
|
|
||||||
} else {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// liste à plusieurs élements...
|
|
||||||
if (strcmp(currSpaceId, spaceId) == 0) {
|
|
||||||
// ca correspond
|
|
||||||
if (strcmp(prevElemId, currElemId) == 0) {
|
|
||||||
// si on est en début de liste (prev=current)
|
|
||||||
// - la tete de liste pointe sur le suivant
|
|
||||||
strcpy(list->headId,
|
|
||||||
nextElemId);
|
|
||||||
} else {
|
|
||||||
if (strcmp
|
|
||||||
(currElemId,
|
|
||||||
nextElemId) == 0) {
|
|
||||||
// si on est en find de liste (current=next)
|
|
||||||
// - on fait pointer la queue de liste sur le précédent
|
|
||||||
strcpy(list->tailId,
|
|
||||||
prevElemId);
|
|
||||||
// - on fait pointer le précédent sur lui-meme
|
|
||||||
prevElem =
|
|
||||||
msgSpaceListElemOpen
|
|
||||||
(prevElemId);
|
|
||||||
strcpy(prevElem->next,
|
|
||||||
prevElemId);
|
|
||||||
msgSpaceListElemClose
|
|
||||||
(prevElem);
|
|
||||||
} else {
|
|
||||||
// on est en milieu de liste
|
|
||||||
// - on fait pointer le précédent sur le suivant
|
|
||||||
prevElem =
|
|
||||||
msgSpaceListElemOpen
|
|
||||||
(prevElemId);
|
|
||||||
strcpy(prevElem->next,
|
|
||||||
nextElemId);
|
|
||||||
msgSpaceListElemClose
|
|
||||||
(prevElem);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// - on détruit l'actuel
|
|
||||||
shm_unlink(currElemId);
|
|
||||||
found = true;
|
|
||||||
break;
|
|
||||||
} else {
|
|
||||||
//cela ne correspond pas
|
|
||||||
//on recopie
|
|
||||||
strcpy(prevElemId, currElemId);
|
|
||||||
strcpy(currElemId, nextElemId);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
if (msgSpaceListClose(list) < 0) {
|
|
||||||
NZG_ERROR("msgSpaceListClose", "");
|
|
||||||
goto ERROR;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
ERROR:
|
if (msgSpaceListClose(list) < 0){
|
||||||
return -1;
|
NZG_ERROR("msgSpaceListClose","");
|
||||||
|
goto ERROR;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
ERROR:
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,26 +2,25 @@
|
||||||
#include "ids.h"
|
#include "ids.h"
|
||||||
|
|
||||||
/* prototypes des fonctions annexes à ne pas exporter */
|
/* prototypes des fonctions annexes à ne pas exporter */
|
||||||
int msgSpaceIdIntern(msgSpaceId dest, const msgSpaceId src);
|
int msgSpaceIdIntern(msgSpaceId dest,const msgSpaceId src );
|
||||||
int msgPoolDataIdIntern(msgSpaceId dest, const msgSpaceId src);
|
int msgPoolDataIdIntern(msgSpaceId dest,const msgSpaceId src );
|
||||||
|
|
||||||
msgSpace *msgSpaceOpen(msgSpaceId externId)
|
|
||||||
{
|
|
||||||
int shmFd;
|
|
||||||
msgSpaceId nzgId;
|
|
||||||
msgSpace *mSAddr;
|
|
||||||
if (msgSpaceIdIntern(nzgId, externId) < 0) {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
if ((shmFd = shm_open(nzgId, O_RDWR, MSGSPACE_DEFAULT_MODE)) < 0) {
|
|
||||||
perror("shm_open");
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
mSAddr =
|
|
||||||
mmap(NULL, sizeof(msgSpace), PROT_READ | PROT_WRITE, MAP_SHARED,
|
|
||||||
shmFd, (off_t) 0);
|
|
||||||
|
|
||||||
printf("OPEN: msgSpace mapped to %p in %d\n", (void *)mSAddr,
|
msgSpace * msgSpaceOpen(msgSpaceId externId){
|
||||||
(int)getpid());
|
int shmFd;
|
||||||
return mSAddr;
|
msgSpaceId nzgId;
|
||||||
|
msgSpace * mSAddr;
|
||||||
|
if (msgSpaceIdIntern(nzgId,externId) < 0){
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
if ((shmFd=shm_open(nzgId,O_RDWR,MSGSPACE_DEFAULT_MODE)) < 0){
|
||||||
|
perror("shm_open");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
mSAddr=mmap(NULL,sizeof(msgSpace),PROT_READ|PROT_WRITE,MAP_SHARED,shmFd,(off_t)0);
|
||||||
|
|
||||||
|
printf( "OPEN: msgSpace mapped to 0x%08x in %d\n", (int)mSAddr,(int)getpid());
|
||||||
|
return mSAddr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1 +1,2 @@
|
||||||
#include "libnazgul.h"
|
#include "libnazgul.h"
|
||||||
|
|
||||||
|
|
|
@ -68,3 +68,5 @@ clean:
|
||||||
% : %.c
|
% : %.c
|
||||||
$(CC) -o $* $< $(INCLUDES) $(LIBINC) $(LIBS) $(CFLAGS) $(DEFS)
|
$(CC) -o $* $< $(INCLUDES) $(LIBINC) $(LIBS) $(CFLAGS) $(DEFS)
|
||||||
|
|
||||||
|
edit:
|
||||||
|
gvim *.h *.c
|
||||||
|
|
67
test/create_delete.c
Normal file
67
test/create_delete.c
Normal file
|
@ -0,0 +1,67 @@
|
||||||
|
#ifdef _NZG_HPUX
|
||||||
|
#include <sys/wait.h>
|
||||||
|
#else
|
||||||
|
#include <wait.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "libnazgul.h"
|
||||||
|
|
||||||
|
int main(void) {
|
||||||
|
// msgSpace mS=0;
|
||||||
|
|
||||||
|
pid_t pid;
|
||||||
|
msgSpaceId testId;
|
||||||
|
msgSpace * mSPAC;
|
||||||
|
msgPool poolInfos[3];
|
||||||
|
char * montext;
|
||||||
|
|
||||||
|
poolInfos[0].bufferNb=4;
|
||||||
|
poolInfos[0].bufferSize=200;
|
||||||
|
|
||||||
|
poolInfos[1].bufferNb=5;
|
||||||
|
poolInfos[1].bufferSize=250;
|
||||||
|
|
||||||
|
poolInfos[2].bufferNb=5;
|
||||||
|
poolInfos[2].bufferSize=280;
|
||||||
|
|
||||||
|
sprintf(testId,"test%d",(int)getuid());
|
||||||
|
printf("RequestedId: %s\n",testId);
|
||||||
|
printf("Void size: %d\n",(int)sizeof(void));
|
||||||
|
mSPAC=msgSpaceCreate(testId,0,3,poolInfos);
|
||||||
|
if (mSPAC ==NULL) {
|
||||||
|
NZG_ERROR("msgSpaceCreate",testId);
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
pid=fork();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if (pid ==0){
|
||||||
|
mSPAC=msgSpaceOpen(testId);
|
||||||
|
sleep(5);
|
||||||
|
montext=msgAllocate(mSPAC,2,180,0);
|
||||||
|
sleep(5);
|
||||||
|
montext=msgAllocate(mSPAC,2,170,0);
|
||||||
|
sleep(5);
|
||||||
|
montext=msgAllocate(mSPAC,2,270,0);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
mSPAC=msgSpaceOpen(testId);
|
||||||
|
montext=msgAllocate(mSPAC,2,280,0);
|
||||||
|
*montext=42;
|
||||||
|
printf("### test Valeur0 %d ###\n",(int)*montext);
|
||||||
|
//sleep(2);
|
||||||
|
montext=msgAllocate(mSPAC,2,270,0);
|
||||||
|
*montext=17;
|
||||||
|
printf("### test Valeur1 %d ###\n",(int)*montext);
|
||||||
|
sleep(5);
|
||||||
|
montext=msgAllocate(mSPAC,2,270,0);
|
||||||
|
msgFree(mSPAC,(void *)montext);
|
||||||
|
//msgFree(mSPAC,(void *)montext);
|
||||||
|
//msgFree(mSPAC,(void *)montext);
|
||||||
|
wait(NULL);
|
||||||
|
msgSpaceDelete(testId);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
100
test/msgSpaceState.c
Normal file
100
test/msgSpaceState.c
Normal file
|
@ -0,0 +1,100 @@
|
||||||
|
#ifdef _NZG_HPUX
|
||||||
|
#include <sys/wait.h>
|
||||||
|
#else
|
||||||
|
#include <wait.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "libnazgul.h"
|
||||||
|
|
||||||
|
void usage(char * myname){
|
||||||
|
printf("Usage: %s [--all | msgSpaceId1 msgSpaceId2 ... ]\n",myname);
|
||||||
|
}
|
||||||
|
|
||||||
|
int about(char * spaceId){
|
||||||
|
msgPoolDataTabSemId ressourceSemId;
|
||||||
|
sem_t * ressourceSemFd;
|
||||||
|
int i;
|
||||||
|
msgPoolData * poolDataTab;
|
||||||
|
msgSpace * space;
|
||||||
|
int ressourceSemVal;
|
||||||
|
if (strlen(spaceId)> MSGSPACE_ID_LEN){
|
||||||
|
//verif de la longueur
|
||||||
|
fprintf(stderr,"Too long ident : %s\n",spaceId);
|
||||||
|
goto ERROR;
|
||||||
|
} else {
|
||||||
|
int err;
|
||||||
|
msgSpaceListLock();
|
||||||
|
err=msgSpaceListFindId(spaceId);
|
||||||
|
msgSpaceListUnlock();
|
||||||
|
if (err < 1){
|
||||||
|
if (err==0){
|
||||||
|
// le msgSpace existe
|
||||||
|
space=msgSpaceOpen(spaceId);
|
||||||
|
// on lit les informations sur le msgSpace
|
||||||
|
// les pool
|
||||||
|
for (i=0;i<space->poolNb;i++){
|
||||||
|
msgPoolSemIdIntern(ressourceSemId,space->externId,i);
|
||||||
|
ressourceSemFd = sem_open(ressourceSemId,O_CREAT,SEM_DEFAULT_MODE,0);
|
||||||
|
if (ressourceSemFd == SEM_FAILED){
|
||||||
|
NZG_ERROR("sem_open",ressourceSemId);
|
||||||
|
goto ERROR;
|
||||||
|
}
|
||||||
|
if (sem_getvalue(ressourceSemFd, &ressourceSemVal) < 0){
|
||||||
|
NZG_ERROR("sem_getvalue",ressourceSemId);
|
||||||
|
goto ERROR;
|
||||||
|
}
|
||||||
|
msgPoolDataTabLock(space);
|
||||||
|
poolDataTab= msgPoolDataTabOpen(space);
|
||||||
|
// donner le nombre de buffer disponibles
|
||||||
|
printf("- %d/%d free buffers in pool #%d\n",
|
||||||
|
ressourceSemVal,
|
||||||
|
poolDataTab[i].bufferNb,
|
||||||
|
i);
|
||||||
|
msgPoolDataTabClose(space,poolDataTab);
|
||||||
|
msgPoolDataTabUnlock(space);
|
||||||
|
if(sem_close(ressourceSemFd) <0){
|
||||||
|
NZG_ERROR("sem_getvalue",ressourceSemId);
|
||||||
|
goto ERROR;
|
||||||
|
}
|
||||||
|
// pour chaque buffer, dire s'il est libre ou pas
|
||||||
|
// et le processus/addresse associé
|
||||||
|
}
|
||||||
|
msgSpaceClose(space);
|
||||||
|
} else {
|
||||||
|
// zut, il y a soit une erreur
|
||||||
|
NZG_ERROR("spaceListFindId : error ",spaceId);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// on quitte : l'element n'existe
|
||||||
|
fprintf(stderr,"Ident %s does not exist.\n",spaceId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
ERROR:
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc,char **argv){
|
||||||
|
printf("Args %d\n",argc);
|
||||||
|
if (argc<2){
|
||||||
|
usage(argv[0]);
|
||||||
|
}else {
|
||||||
|
if (argc==2){
|
||||||
|
if (strcmp("--all",argv[1])==0){
|
||||||
|
// listing
|
||||||
|
printf("[ Listing of msgSpaces ]\n");
|
||||||
|
} else {
|
||||||
|
// only one msgSpaceId
|
||||||
|
printf("[ About %s ]\n",argv[1]);
|
||||||
|
about(argv[1]);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
int i;
|
||||||
|
for (i=1;i<argc;i++){
|
||||||
|
printf("[ About %s ]\n",argv[i]);
|
||||||
|
about(argv[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
54
test/put_get_mono.c
Normal file
54
test/put_get_mono.c
Normal file
|
@ -0,0 +1,54 @@
|
||||||
|
#ifdef _NZG_HPUX
|
||||||
|
#include <sys/wait.h>
|
||||||
|
#else
|
||||||
|
#include <wait.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "libnazgul.h"
|
||||||
|
|
||||||
|
int main(void) {
|
||||||
|
// msgSpace mS=0;
|
||||||
|
|
||||||
|
msgSpaceId testId;
|
||||||
|
msgSpace * mSPAC;
|
||||||
|
msgPool poolInfos[3];
|
||||||
|
char * montext;
|
||||||
|
|
||||||
|
poolInfos[0].bufferNb=4;
|
||||||
|
poolInfos[0].bufferSize=200;
|
||||||
|
|
||||||
|
poolInfos[1].bufferNb=5;
|
||||||
|
poolInfos[1].bufferSize=250;
|
||||||
|
|
||||||
|
sprintf(testId,"test%d",(int)getuid());
|
||||||
|
printf("RequestedId: %s\n",testId);
|
||||||
|
printf("Void size: %d\n",(int)sizeof(void));
|
||||||
|
//creation de l'espace de messages
|
||||||
|
mSPAC=msgSpaceCreate(testId,1,2,poolInfos);
|
||||||
|
if (mSPAC ==NULL) {
|
||||||
|
NZG_ERROR("msgSpaceCreate",testId);
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("CREATION ------------------ ok\n");
|
||||||
|
|
||||||
|
mSPAC=msgSpaceOpen(testId);
|
||||||
|
|
||||||
|
/***** TEST 1 *****/
|
||||||
|
montext=msgAllocate(mSPAC,1,280,0);
|
||||||
|
*montext=42;
|
||||||
|
printf("### test Valeur0 %d ###\n",(int)*montext);
|
||||||
|
printf("Put..."); fflush(stdout);
|
||||||
|
msgPut(mSPAC,0,montext);
|
||||||
|
printf("put-ok\n");
|
||||||
|
|
||||||
|
|
||||||
|
printf("Get..."); fflush(stdout);
|
||||||
|
montext=msgGet(mSPAC,0,0);
|
||||||
|
printf("get-ok\n");
|
||||||
|
printf("### test Reception %d ###\n",(int)*montext);
|
||||||
|
msgFree(mSPAC,montext);
|
||||||
|
/***** TEST 1 *****/
|
||||||
|
msgSpaceDelete(testId);
|
||||||
|
return 0;
|
||||||
|
}
|
55
test/put_get_multi.c
Normal file
55
test/put_get_multi.c
Normal file
|
@ -0,0 +1,55 @@
|
||||||
|
#ifdef _NZG_HPUX
|
||||||
|
#include <sys/wait.h>
|
||||||
|
#else
|
||||||
|
#include <wait.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "libnazgul.h"
|
||||||
|
|
||||||
|
int main(void) {
|
||||||
|
// msgSpace mS=0;
|
||||||
|
|
||||||
|
msgSpaceId testId;
|
||||||
|
msgSpace * mSPAC;
|
||||||
|
msgPool poolInfos[3];
|
||||||
|
char * montext;
|
||||||
|
|
||||||
|
poolInfos[0].bufferNb=4;
|
||||||
|
poolInfos[0].bufferSize=200;
|
||||||
|
|
||||||
|
poolInfos[1].bufferNb=5;
|
||||||
|
poolInfos[1].bufferSize=250;
|
||||||
|
|
||||||
|
sprintf(testId,"test%d",(int)getuid());
|
||||||
|
printf("RequestedId: %s\n",testId);
|
||||||
|
printf("Void size: %d\n",(int)sizeof(void));
|
||||||
|
//creation de l'espace de messages
|
||||||
|
mSPAC=msgSpaceCreate(testId,1,2,poolInfos);
|
||||||
|
if (mSPAC ==NULL) {
|
||||||
|
NZG_ERROR("msgSpaceCreate",testId);
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("CREATION ------------------ ok\n");
|
||||||
|
pid_t pid=fork();
|
||||||
|
if (pid==0){
|
||||||
|
sleep(2);
|
||||||
|
mSPAC=msgSpaceOpen(testId);
|
||||||
|
montext=msgAllocate(mSPAC,1,280,0);
|
||||||
|
*montext=42;
|
||||||
|
printf("### test Valeur0 %d ###\n",(int)*montext);
|
||||||
|
printf("Put1..."); fflush(stdout);
|
||||||
|
msgPut(mSPAC,0,montext);
|
||||||
|
printf("put1-ok\n");
|
||||||
|
} else {
|
||||||
|
mSPAC=msgSpaceOpen(testId);
|
||||||
|
printf("Get..."); fflush(stdout);
|
||||||
|
montext=msgGet(mSPAC,0,0);
|
||||||
|
printf("get-ok\n");
|
||||||
|
printf("### test Reception %d ###\n",(int)*montext);
|
||||||
|
msgFree(mSPAC,montext);
|
||||||
|
wait(NULL);
|
||||||
|
msgSpaceDelete(testId);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
|
@ -1,66 +0,0 @@
|
||||||
#ifdef _NZG_HPUX
|
|
||||||
#include <sys/wait.h>
|
|
||||||
#else
|
|
||||||
#include <wait.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "libnazgul.h"
|
|
||||||
|
|
||||||
int main(void)
|
|
||||||
{
|
|
||||||
// msgSpace mS=0;
|
|
||||||
|
|
||||||
pid_t pid;
|
|
||||||
msgSpaceId testId;
|
|
||||||
msgSpace *mSPAC;
|
|
||||||
msgPool poolInfos[3];
|
|
||||||
char *montext;
|
|
||||||
|
|
||||||
poolInfos[0].bufferNb = 4;
|
|
||||||
poolInfos[0].bufferSize = 200;
|
|
||||||
|
|
||||||
poolInfos[1].bufferNb = 5;
|
|
||||||
poolInfos[1].bufferSize = 250;
|
|
||||||
|
|
||||||
poolInfos[2].bufferNb = 5;
|
|
||||||
poolInfos[2].bufferSize = 280;
|
|
||||||
|
|
||||||
sprintf(testId, "test%d", (int)getuid());
|
|
||||||
printf("RequestedId: %s\n", testId);
|
|
||||||
printf("Void size: %d\n", (int)sizeof(void));
|
|
||||||
mSPAC = msgSpaceCreate(testId, 0, 3, poolInfos);
|
|
||||||
if (mSPAC == NULL) {
|
|
||||||
NZG_ERROR("msgSpaceCreate", testId);
|
|
||||||
exit(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
pid = fork();
|
|
||||||
|
|
||||||
if (pid == 0) {
|
|
||||||
mSPAC = msgSpaceOpen(testId);
|
|
||||||
sleep(5);
|
|
||||||
montext = msgAllocate(mSPAC, 2, 180, 0);
|
|
||||||
sleep(5);
|
|
||||||
montext = msgAllocate(mSPAC, 2, 170, 0);
|
|
||||||
sleep(5);
|
|
||||||
montext = msgAllocate(mSPAC, 2, 270, 0);
|
|
||||||
|
|
||||||
} else {
|
|
||||||
mSPAC = msgSpaceOpen(testId);
|
|
||||||
montext = msgAllocate(mSPAC, 2, 280, 0);
|
|
||||||
*montext = 42;
|
|
||||||
printf("### test Valeur0 %d ###\n", (int)*montext);
|
|
||||||
//sleep(2);
|
|
||||||
montext = msgAllocate(mSPAC, 2, 270, 0);
|
|
||||||
*montext = 17;
|
|
||||||
printf("### test Valeur1 %d ###\n", (int)*montext);
|
|
||||||
sleep(5);
|
|
||||||
montext = msgAllocate(mSPAC, 2, 270, 0);
|
|
||||||
msgFree(mSPAC, (void *)montext);
|
|
||||||
//msgFree(mSPAC,(void *)montext);
|
|
||||||
//msgFree(mSPAC,(void *)montext);
|
|
||||||
wait(NULL);
|
|
||||||
msgSpaceDelete(testId);
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
|
@ -1,111 +0,0 @@
|
||||||
#ifdef _NZG_HPUX
|
|
||||||
#include <sys/wait.h>
|
|
||||||
#else
|
|
||||||
#include <wait.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "libnazgul.h"
|
|
||||||
|
|
||||||
void usage(char *myname)
|
|
||||||
{
|
|
||||||
printf("Usage: %s [--all | msgSpaceId1 msgSpaceId2 ... ]\n", myname);
|
|
||||||
}
|
|
||||||
|
|
||||||
int about(char *spaceId)
|
|
||||||
{
|
|
||||||
msgPoolDataTabSemId ressourceSemId;
|
|
||||||
sem_t *ressourceSemFd;
|
|
||||||
int i;
|
|
||||||
msgPoolData *poolDataTab;
|
|
||||||
msgSpace *space;
|
|
||||||
int ressourceSemVal;
|
|
||||||
if (strlen(spaceId) > MSGSPACE_ID_LEN) {
|
|
||||||
//verif de la longueur
|
|
||||||
fprintf(stderr, "Too long ident : %s\n", spaceId);
|
|
||||||
goto ERROR;
|
|
||||||
} else {
|
|
||||||
int err;
|
|
||||||
msgSpaceListLock();
|
|
||||||
err = msgSpaceListFindId(spaceId);
|
|
||||||
msgSpaceListUnlock();
|
|
||||||
if (err < 1) {
|
|
||||||
if (err == 0) {
|
|
||||||
// le msgSpace existe
|
|
||||||
space = msgSpaceOpen(spaceId);
|
|
||||||
// on lit les informations sur le msgSpace
|
|
||||||
// les pool
|
|
||||||
for (i = 0; i < space->poolNb; i++) {
|
|
||||||
msgPoolSemIdIntern(ressourceSemId,
|
|
||||||
space->externId, i);
|
|
||||||
ressourceSemFd =
|
|
||||||
sem_open(ressourceSemId, O_CREAT,
|
|
||||||
SEM_DEFAULT_MODE, 0);
|
|
||||||
if (ressourceSemFd == SEM_FAILED) {
|
|
||||||
NZG_ERROR("sem_open",
|
|
||||||
ressourceSemId);
|
|
||||||
goto ERROR;
|
|
||||||
}
|
|
||||||
if (sem_getvalue
|
|
||||||
(ressourceSemFd,
|
|
||||||
&ressourceSemVal) < 0) {
|
|
||||||
NZG_ERROR("sem_getvalue",
|
|
||||||
ressourceSemId);
|
|
||||||
goto ERROR;
|
|
||||||
}
|
|
||||||
msgPoolDataTabLock(space);
|
|
||||||
poolDataTab = msgPoolDataTabOpen(space);
|
|
||||||
// donner le nombre de buffer disponibles
|
|
||||||
printf
|
|
||||||
("- %d/%d free buffers in pool #%d\n",
|
|
||||||
ressourceSemVal,
|
|
||||||
poolDataTab[i].bufferNb, i);
|
|
||||||
msgPoolDataTabClose(space, poolDataTab);
|
|
||||||
msgPoolDataTabUnlock(space);
|
|
||||||
if (sem_close(ressourceSemFd) < 0) {
|
|
||||||
NZG_ERROR("sem_getvalue",
|
|
||||||
ressourceSemId);
|
|
||||||
goto ERROR;
|
|
||||||
}
|
|
||||||
// pour chaque buffer, dire s'il est libre ou pas
|
|
||||||
// et le processus/addresse associé
|
|
||||||
}
|
|
||||||
msgSpaceClose(space);
|
|
||||||
} else {
|
|
||||||
// zut, il y a soit une erreur
|
|
||||||
NZG_ERROR("spaceListFindId : error ", spaceId);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// on quitte : l'element n'existe
|
|
||||||
fprintf(stderr, "Ident %s does not exist.\n", spaceId);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
ERROR:
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
|
||||||
{
|
|
||||||
printf("Args %d\n", argc);
|
|
||||||
if (argc < 2) {
|
|
||||||
usage(argv[0]);
|
|
||||||
} else {
|
|
||||||
if (argc == 2) {
|
|
||||||
if (strcmp("--all", argv[1]) == 0) {
|
|
||||||
// listing
|
|
||||||
printf("[ Listing of msgSpaces ]\n");
|
|
||||||
} else {
|
|
||||||
// only one msgSpaceId
|
|
||||||
printf("[ About %s ]\n", argv[1]);
|
|
||||||
about(argv[1]);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
int i;
|
|
||||||
for (i = 1; i < argc; i++) {
|
|
||||||
printf("[ About %s ]\n", argv[i]);
|
|
||||||
about(argv[i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
|
@ -1,56 +0,0 @@
|
||||||
#ifdef _NZG_HPUX
|
|
||||||
#include <sys/wait.h>
|
|
||||||
#else
|
|
||||||
#include <wait.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "libnazgul.h"
|
|
||||||
|
|
||||||
int main(void)
|
|
||||||
{
|
|
||||||
// msgSpace mS=0;
|
|
||||||
|
|
||||||
msgSpaceId testId;
|
|
||||||
msgSpace *mSPAC;
|
|
||||||
msgPool poolInfos[3];
|
|
||||||
char *montext;
|
|
||||||
|
|
||||||
poolInfos[0].bufferNb = 4;
|
|
||||||
poolInfos[0].bufferSize = 200;
|
|
||||||
|
|
||||||
poolInfos[1].bufferNb = 5;
|
|
||||||
poolInfos[1].bufferSize = 250;
|
|
||||||
|
|
||||||
sprintf(testId, "test%d", (int)getuid());
|
|
||||||
printf("RequestedId: %s\n", testId);
|
|
||||||
printf("Void size: %d\n", (int)sizeof(void));
|
|
||||||
//creation de l'espace de messages
|
|
||||||
mSPAC = msgSpaceCreate(testId, 1, 2, poolInfos);
|
|
||||||
if (mSPAC == NULL) {
|
|
||||||
NZG_ERROR("msgSpaceCreate", testId);
|
|
||||||
exit(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
printf("CREATION ------------------ ok\n");
|
|
||||||
|
|
||||||
mSPAC = msgSpaceOpen(testId);
|
|
||||||
|
|
||||||
/***** TEST 1 *****/
|
|
||||||
montext = msgAllocate(mSPAC, 1, 280, 0);
|
|
||||||
*montext = 42;
|
|
||||||
printf("### test Valeur0 %d ###\n", (int)*montext);
|
|
||||||
printf("Put...");
|
|
||||||
fflush(stdout);
|
|
||||||
msgPut(mSPAC, 0, montext);
|
|
||||||
printf("put-ok\n");
|
|
||||||
|
|
||||||
printf("Get...");
|
|
||||||
fflush(stdout);
|
|
||||||
montext = msgGet(mSPAC, 0, 0);
|
|
||||||
printf("get-ok\n");
|
|
||||||
printf("### test Reception %d ###\n", (int)*montext);
|
|
||||||
msgFree(mSPAC, montext);
|
|
||||||
/***** TEST 1 *****/
|
|
||||||
msgSpaceDelete(testId);
|
|
||||||
return 0;
|
|
||||||
}
|
|
|
@ -1,58 +0,0 @@
|
||||||
#ifdef _NZG_HPUX
|
|
||||||
#include <sys/wait.h>
|
|
||||||
#else
|
|
||||||
#include <wait.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "libnazgul.h"
|
|
||||||
|
|
||||||
int main(void)
|
|
||||||
{
|
|
||||||
// msgSpace mS=0;
|
|
||||||
|
|
||||||
msgSpaceId testId;
|
|
||||||
msgSpace *mSPAC;
|
|
||||||
msgPool poolInfos[3];
|
|
||||||
char *montext;
|
|
||||||
|
|
||||||
poolInfos[0].bufferNb = 4;
|
|
||||||
poolInfos[0].bufferSize = 200;
|
|
||||||
|
|
||||||
poolInfos[1].bufferNb = 5;
|
|
||||||
poolInfos[1].bufferSize = 250;
|
|
||||||
|
|
||||||
sprintf(testId, "test%d", (int)getuid());
|
|
||||||
printf("RequestedId: %s\n", testId);
|
|
||||||
printf("Void size: %d\n", (int)sizeof(void));
|
|
||||||
//creation de l'espace de messages
|
|
||||||
mSPAC = msgSpaceCreate(testId, 1, 2, poolInfos);
|
|
||||||
if (mSPAC == NULL) {
|
|
||||||
NZG_ERROR("msgSpaceCreate", testId);
|
|
||||||
exit(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
printf("CREATION ------------------ ok\n");
|
|
||||||
pid_t pid = fork();
|
|
||||||
if (pid == 0) {
|
|
||||||
sleep(2);
|
|
||||||
mSPAC = msgSpaceOpen(testId);
|
|
||||||
montext = msgAllocate(mSPAC, 1, 280, 0);
|
|
||||||
*montext = 42;
|
|
||||||
printf("### test Valeur0 %d ###\n", (int)*montext);
|
|
||||||
printf("Put1...");
|
|
||||||
fflush(stdout);
|
|
||||||
msgPut(mSPAC, 0, montext);
|
|
||||||
printf("put1-ok\n");
|
|
||||||
} else {
|
|
||||||
mSPAC = msgSpaceOpen(testId);
|
|
||||||
printf("Get...");
|
|
||||||
fflush(stdout);
|
|
||||||
montext = msgGet(mSPAC, 0, 0);
|
|
||||||
printf("get-ok\n");
|
|
||||||
printf("### test Reception %d ###\n", (int)*montext);
|
|
||||||
msgFree(mSPAC, montext);
|
|
||||||
wait(NULL);
|
|
||||||
msgSpaceDelete(testId);
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
Loading…
Add table
Reference in a new issue