aboutsummaryrefslogtreecommitdiffstats
path: root/erts/emulator/nifs/common/socket_nif.c
AgeCommit message (Collapse)Author
2019-03-18Merge branch 'bmk/20190315/use_wrong_current_when_stopping'Micael Karlberg
2019-03-15[socket] Fixing debug printoutMicael Karlberg
A debug printout in the socket_stop fucntion used the wrong requestor record for the pid, which may leasd to a confusing debug printout.
2019-03-14[socket] The activate-next always used read selectMicael Karlberg
The activate-next (reader|writer|acceptor) always *incorrectly* used the read select function. This has now been changed so that the functions are created via a macro with an argument specifying which select function to use.
2019-03-06[socket] More if-def to make it "work" on windowsMicael Karlberg
2019-03-06[socket] Use (new) enif_compare_pids functionMicael Karlberg
Replace the won function for pid compare with the (new) enif_compare_pids function. OTP-15565
2019-03-06[socket] CommentaryMicael Karlberg
Add some more comments in order to increase readability. OTP-15565
2019-03-06[socket] Macro abuse of activate-nextMicael Karlberg
Implemented the activate_next function and added its "users" acceptor, writer and reader (macro abuse). After a request (accept, write or send) has been either successfully completed or failed, another request should be activated. Previously only one attempt was made, which might leave the other (waiting) requestors hanging. Now, instead we use a 'activate-next' function that pop's the request (accept, wrote or read) queue until success or its empty, thereby making sure that no waiting processes is left hanging. OTP-15565
2019-03-05[socket] Make use of official monitor to term functionMicael Karlberg
Remove own function to make monitor printable (was a hack) and make use of the new enif_make_monitor_term instead.
2019-03-04Merge branch 'bmk/20190304/openindiana_types' into ↵Micael Karlberg
bmk/20190301/cleanup_through_macro_abuse/OTP-15565
2019-03-04[socket] Fixed various type size and unused function warningsMicael Karlberg
Fixed some type size warnings (SCTP related). E.g: On Solaris 11 (OpenIndiana Hipster) long and int is size 4, but the way Sint32 def works it first "tests" for long size and if that is correct, that is chosen (which it is on Solaris 11). On linux long is size 8, so Sint32 will be defined as int. ... On Solaris 11 the flags TCP_CONGESTION and SO_BINDTODEVICE does not exist, so the function(s) n[set|get]opt_str_opt is never used. So, in order to keep the compiler quiet, we add some if-def to exclude these functions in this case.
2019-03-04[socket] Some minor cleanup and commentsMicael Karlberg
2019-03-04[socket] Macro abuse for requestor queue func defMicael Karlberg
The requestor (acceptor, writer and reader) functions are virtually identical, so to ensure quality and not having to write the exact same functions three times, we make use of some macro magic for their declaration. OTP-15565
2019-03-04[net] Macro abuse for func defMicael Karlberg
Some more macro abuse for nif API callback functions. OTP-15565
2019-03-04[socket] Macro abuse for more func defMicael Karlberg
Some more macro abuse for nif API callback functions and the operator (acceptor, writer and reader) queue wrapper functions (search4pid, push, pop and unqueue). OTP-15565
2019-03-04[socket] Macro abuse for setopt(otp) and getopt(otp)Micael Karlberg
2019-03-04[socket|net] Macro abuseMicael Karlberg
Make use of macro concat magic to simplify declarations. OTP-15565
2019-02-22[socket] Cleanup and accept restructureMicael Karlberg
Some cleanup (of open, bind, connect) and rewrote the accept code (moved the code into smaller functions). OTP-14831
2019-02-22[socket] More fixes to socket closeMicael Karlberg
Better handling of socket close. The 'closeRef' needed its own environment to make if work in both cases (both called and scheduled). Also Introduced the enif select wrapper functions (read, write, stop and cancel). Also add error handling at every time one of these functions are called. OTP-14831
2019-02-22[socket] Fixed socket close bugMicael Karlberg
Fixed a raise condition bug in the socket_stop (callback) function that could result in the socket actually *not* beeing closed. OTP-14831
2019-02-22[socket-nif] Fix buggy use of NULL-monitorSverker Eriksson
Assert failed in enif_demonitor when called with "NULL-monitor". Replaced null monitor with separate 'is_active' boolean and added my_make_monitor_term for printing (to be replaced with enif_make_monitor_term).
2019-02-22[socket-nif] Fix bug in message sendingSverker Eriksson
Asserts failed in debug vm as msg term was built from mixed ErlNifEnv's.
2019-02-22[socket-nif] Fix memorys leaks in recv error casesSverker Eriksson
and collapsed some duplicate code
2019-02-22[socket-nif] Fix currentReader/Writer always set at enif_selectSverker Eriksson
2019-02-22[socket-nif] Rename 'nosup' -> 'notsup'Sverker Eriksson
as called in crypto.erl and erlang.erl.
2019-02-01[socket-nif] nosup expection of win32 and type(s) replacementsMicael Karlberg
The nif callback functions (nif_open) now instead cause an 'nosup' exception if called (instead of badarg). The basic type uint16_t, uint32_t and int32_t (C99) replaced "own" (that is, defined by "us") types Uint16, Uint32 and Sint32. The point of this is that our Windows build system seems to be a bit lacking when it comes to types... Removed "some stuff" that was if-defed. Different solution when win32 support for sockets has been improved. Make sure the socket_*.c util modules are not included in the building for windows. OTP-15526
2019-01-30[socket-nif] Preliminary windows adaptionsMicael Karlberg
Added preliminary, and temporary, windows adaptions. Basically they amount to letting all nif-callback functions returning badarg for all calls if on windows (this has been accomplished by if-defing the nif-code; if win32 then badarg else do-something). OTP-15526
2019-01-29[socket-nif] The otp rcvbuf option updatedMicael Karlberg
Its now possible to set a rcvbuf (otp) option value of {N :: pos_integer(), BufSz :: pos_integer()}. This value is used for type stream and protocol tcp, when calling the function recv with length = 0 (zero). The second value, BufSz, is the actual size of the receive buffer used when calling the socket recv function, and the first value, N, is the max number of possible reads that will be performed (at most), even if there is more data to read. This is limit the effect of DoS attacks. OTP-15497
2019-01-25[socket-nif] Correct state checks when calling read and write functionsMicael Karlberg
The read and write functions now *only* use the isReadable and isWritable fields, respectively, to decide if the "socket" can be read from and written to (previously the state field was used outside of the mutex lock). Also made it possible to enable / disable test suite groups individually, via environment variables (ESOCK_TEST_...). Specifically, the ttest group has been excluded by default (takes to long a time). OTP-15549
2019-01-21[socket-nif] Add support for otp option fdMicael Karlberg
Add a way to *get* the file descriptor (fd) of a socket. Useful mostly for debugging. OTP-15528
2018-12-21[socket-nif] Fixed OpenBSD configMicael Karlberg
The macro (define) IPTOS_MINCOST does not exist on OpenBSD 6.3. OTP-14831
2018-12-14[socket-nif] Message interface between socket.erl and nif updatedMicael Karlberg
Previously the "message interface" between the functions in socket.erl and the nif-code (socket_nif.c) was "ad hoc". This has now been changed so that we have a unified message {'$socket', SockRef | undefined, Tag, Info} This also has the added advantage of preparing the code for when we start using the new select-fucntions (with which its possible to specify your own message). This will be used in order to get around our eterm "leak" (we will use a simple counter, maintained in the nif, instead of the [Recv|Send|Acc]Ref we generate in the erlang code today. OTP-14831
2018-12-06[socket-nif] Valgrind: plugged memory leaks in nif_[recvfrom<recvmsg]Micael Karlberg
"Dry fixed" the "same" problems as was found for nif_recv (missing binary free(s)). OTP-14831
2018-12-06[socket-nif] Valgrind: plugged memory leaks in nif_recvMicael Karlberg
Running valgrind, found a couple of cases when allocated binaries where not released. Mostly when the recv failed for some reason. Also clear and free the environment associated with the socket (resource) (in the _dtor callback function). OTP-14831
2018-12-05Merge branch 'bmk/20181205/nififying_inet_ttest/OTP-14831' into ↵Micael Karlberg
bmk/20180918/nififying_inet/OTP-14831
2018-12-05[socket-nif] Fixed two minor problems with socket close and downMicael Karlberg
* Socket close callback Only demonitor the closer if its local (close) and its not a direct call. There was a spurious warning message. * Down callback Only process this event if the socket is not closed or closing. OTP-14831
2018-12-05[socket-nif] Increased the default read buffer sizeMicael Karlberg
The default read buffer size was 2K and has now been increased to 8K. OTP-14831
2018-11-27[socket-nif] Conditional use of sctp struct fieldMicael Karlberg
Added config checks for the sctp struct field: sctp_event_subscribe.sctp_authentication_event Also, if-def'ed the code accordingly. If-def'ed code to handle the (non-) existence of IP_PMTUDISC_PROBE and IPV6_PMTUDISC_PROBE for the IP and IPv6 MTU_DISCOVER options. OTP-14831
2018-11-26[socket-nif] Conditional use of sctp struct fieldMicael Karlberg
Added config checks for the sctp struct field: sctp_event_subscribe.sctp_sender_dry_event Also, if-def'ed the code accordingly. OTP-14831
2018-11-06[socket-nif] Badly handled socket close for recvfrom and recvmsgMicael Karlberg
When type = dgram, the functions recvfrom and recvmsg did not properly handle socket close, cuaing the caller to hang indefinitely. OTP-14831
2018-11-05[socket-nif] Sending when buffer is full failedMicael Karlberg
When the send buffer was full (eagain), the send failed (with the rather useless return of {ok, -1}) instead of returning {error, eagain}. OTP-14831
2018-11-02[socket-nif] Inherit buffer sizes when acceptingMicael Karlberg
An "accepted" socket will inherit the parent (listen) socket's buffer sizes (rBufSz, rCtrlSz and wCtrlSz). OTP-14831
2018-11-01[sock-nif|test] Add a ping-pong test caseMicael Karlberg
We got some kind of send hang...
2018-10-30[socket-nif] Add a send and receive chunks test caseMicael Karlberg
The send and recv test case triggered a two bugs. One was that there was no re-selecting when only a portion of the data was received (which meant that we stopped reading). Also, the wrong 'current' (writer) was reset when demonitor current reader after a successful read (which meant that future readers would never have been monitored). OTP-14831
2018-10-22[socket-nif] Initiation of "current reader" missing for recvfromMicael Karlberg
When calling the recvfrom function when there is no data, we should be made wait (for the specified amount of time). But this did not work because the "current reader" structure was not initiated. OTP-14831
2018-10-18[socket-nif] setopt and getopt with level ipv6Micael Karlberg
The level argument for IPv6 can be either SOL_IPV6 or IPPROTO_IPV6, whichever is defined. But it was hard- coded to SOL_IPV6, which is not defined on FreeBSD. OTP-14831
2018-10-18Merge branch 'bmk/20181004/nififying_inet_rework_test_suite/OTP-14831' into ↵Micael Karlberg
bmk/20180918/nififying_inet/OTP-14831
2018-10-18[socket-nif] Initiation of "current reader" missing for recvmsgMicael Karlberg
When calling the recvmsg function when there is no data, we should be wait (for the specified amount of time). But this not not wotk because the "current reader" structure was not initiated. OTP-14831
2018-10-18[socket-nif] Socket closeMicael Karlberg
Fixed a number of issues regarding monitor handling. Monitors are now wrapped in its own type (ESockMonitor). This is hopefully temporary! The reason for this is that there is no way to "initialize" a monitor after a demonitor. This could mean that after a successful demonitor, you could still get a down-callback, and thenh compare with, for instance, ctrlMOn field and get a match, even though it was just (successfully) demonitor'ed. To make debugging easier, the monitor and demonitor calls are now wrapped in their own functions, with debug printouts before and in case of failure, also after the actual calls Also, fixed a number of problems with cancel, where monitors where left still active after cleaning up current and active reader, writer and acceptor. OTP-14831
2018-10-16[socket-nif] Recv handling of closing socketsMicael Karlberg
Fixed more issues regarding closing sockets. Specifically with respect to recv calls. Also, added demonitor for all *current* processes. Also fixed a buffer overflow problem when writing an warning message (the timestamp buffer was not large enough). OTP-14831
2018-10-15[socket-nif] Fix socket close when owner process exitsMicael Karlberg
The handling of terminating controlling-process was incomplete. Also added state check (CLOSED and CLOSING) in all nif-functions to prevent access for a closed (or closing) socket. OTP-14831