[cs631apue] Data structure implementations in <sys/queue.h>

Ramana Nagasamudram rnagasam at stevens.edu
Tue Sep 4 17:14:01 EDT 2018


Thanks for the explanation! On a side note, the list.h implementation in linux (<linux/list.h>) does something very similar (though the macros there seem more complicated). 

I agree with the statement about writing readable and maintainable code. The tricks used in <sys/queue.h> is making it hard for me to gain a good understanding of the implementation. I guess, like you say, time and experience are key.

-----Original Message-----
From: cs631apue-bounces at lists.stevens.edu <cs631apue-bounces at lists.stevens.edu> On Behalf Of cs631apue-request at lists.stevens.edu
Sent: Tuesday, September 4, 2018 7:00 AM
To: cs631apue at lists.stevens.edu
Subject: cs631apue Digest, Vol 36, Issue 2

Send cs631apue mailing list submissions to
	cs631apue at lists.stevens.edu

To subscribe or unsubscribe via the World Wide Web, visit
	https://lists.stevens.edu/mailman/listinfo/cs631apue
or, via email, send a message with subject or body 'help' to
	cs631apue-request at lists.stevens.edu

You can reach the person managing the list at
	cs631apue-owner at lists.stevens.edu

When replying, please edit your Subject line so it is more specific than "Re: Contents of cs631apue digest..."


Today's Topics:

   1. FTP error (Aubhik Mazumdar)
   2. Re: Data structure implementations in <sys/queue.h>
      (Jan Schaumann)
   3. Re: FTP error (Jan Schaumann)


----------------------------------------------------------------------

Message: 1
Date: Mon, 3 Sep 2018 15:21:50 -0400
From: Aubhik Mazumdar <amazumda at stevens.edu>
To: cs631apue at lists.stevens.edu
Subject: [cs631apue] FTP error
Message-ID:
	<CADsh5QFpC-ZfLWpPUz++xyGiBS3A-BD93eMMVH3ccA2OjtP8fg at mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

I have been trying to fetch the course code files using FTP on my MAC OS X but it keeps giving the error- nodename nor servname provided, or not known

I tried the exact command in the lecture01 slides first-

ftp https://www.cs.stevens.edu/~jschauma/631/welcome.c


and others-

ftp http://www.cs.stevens.edu/~jschauma/631/welcome.c

ftp www.cs.stevens.edu/~jschauma/631/welcome.c

ftp ftp://www.cs.stevens.edu/~jschauma/631/welcome.c


I also performed the nslookup and it gives the correct reply with the IP-

Non-authoritative answer:

www.cs.stevens.edu canonical name = https://na01.safelinks.protection.outlook.com/?url=www.cs.stevens-tech.edu&amp;data=02%7C01%7Crnagasam%40stevens.edu%7C85490d813a194921bf5a08d6125598aa%7C8d1a69ec03b54345ae21dad112f5fb4f%7C0%7C0%7C636716556186001278&amp;sdata=gRoSd7oE87ATJ3VvSX6Jv%2FhPhN%2BkhiM8jOo5sV5JAPM%3D&amp;reserved=0.

Name: https://na01.safelinks.protection.outlook.com/?url=www.cs.stevens-tech.edu&amp;data=02%7C01%7Crnagasam%40stevens.edu%7C85490d813a194921bf5a08d6125598aa%7C8d1a69ec03b54345ae21dad112f5fb4f%7C0%7C0%7C636716556186001278&amp;sdata=gRoSd7oE87ATJ3VvSX6Jv%2FhPhN%2BkhiM8jOo5sV5JAPM%3D&amp;reserved=0

Address: 155.246.89.84

I know I can just fetch the code files from github or copy paste them, but I want to diagnose the error. What's funny is that running the same commands on NETBSD works, leading me to think that the ftp implementation in the MAC OS X is slightly different. Is anyone else also facing the same issues?

Thank you,
Aubhik Mazumdar
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.stevens.edu/pipermail/cs631apue/attachments/20180903/7f823dbe/attachment-0001.html>

------------------------------

Message: 2
Date: Mon, 3 Sep 2018 22:42:37 -0400
From: Jan Schaumann <jschauma at stevens.edu>
To: cs631apue at lists.stevens.edu
Subject: Re: [cs631apue] Data structure implementations in
	<sys/queue.h>
Message-ID: <20180904024237.GX14308 at netmeister.org>
Content-Type: text/plain; charset=us-ascii

Ramana Nagasamudram <rnagasam at stevens.edu> wrote:
 
> Could anyone help me understand exactly how this can be more efficient 
> than the alternative?

I have never looked at this in detail, but my guess is:

By not including a reference to the object, you can more easily allocate the data structures and align them at compile time.  Note: the implementation is (almost?) entirely  in macros, so the code is inserted as is at compile time.  By not including a pointer to the object, and instead requiring the object to contain the list head struct, you also yield branchless insertion/deletion in the list: any object can dereference the next item in the list without having to check the reference on the object.

The lack of pointers to the object within the list structure ought to make memory allocation more efficient, which for the purposes of the slist per the header comments and queue(3) description is desirable.

But honestly, the question would likely be better and more completely answered by your Data Structures & Algorithms instructor.

>  Also, <sys/queue.h> seems to be filled with clever tricks.  Where do  
> I start if I want to learn to program like this?

You wouldn't. :-)  By and large what we'll do in _this_ class, anyway, is to stay as far away from clever tricks as possible.  Clever tricks make code hard(er) to read, understand, debug.  We will focus on boring, easy to understand and read code.

(However, if you're interested in optimizing your code, Data Structures & Algorithms is again the best area of expertise to immerse yourself in.
There are several good code-agnostic books on the subject; translating the efficient algorithm into a given language is something that then comes with time and experience.  Online communities and groups can help you practice this, too.)

Hope this helps,
-Jan


------------------------------

Message: 3
Date: Mon, 3 Sep 2018 22:52:26 -0400
From: Jan Schaumann <jschauma at stevens.edu>
To: cs631apue at lists.stevens.edu
Subject: Re: [cs631apue] FTP error
Message-ID: <20180904025226.GY14308 at netmeister.org>
Content-Type: text/plain; charset=us-ascii

Aubhik Mazumdar <amazumda at stevens.edu> wrote:
> I have been trying to fetch the course code files using FTP on my MAC 
> OS X but it keeps giving the error- nodename nor servname provided, or 
> not known

This error should only occur if your system can not resolve the name www.cs.stevens.edu.  You suggest that it can, though, so it's odd that you would see that error.

When describing a problem, it's best to always include the exact and complete input and output of the commands you have problems with.

> I tried the exact command in the lecture01 slides first-
> 
> ftp https://www.cs.stevens.edu/~jschauma/631/welcome.c

What is the _exact_ output of this command?

For example, there's a difference between

ftp: Can't lookup `www.cs.stevens.edu': nodename nor servname provided, or not known

and

ftp: Can't lookup `https': nodename nor servname provided, or not known

In the former case, the command tries to look for 'www.cs.stevens.edu'
and doesn't find the IP address for it; in the second case, it's trying to look for a host named 'https' and can't find that.  (This may be the case if the ftp command in use does not have support for https, for
example.)

It's not clear from your error report which case you are seeing (or if you're seeing another case).

On OS X or other unix variants, you may also try to use curl(1) or
wget(1) instead of ftp(1); the examples given in the slides are intentionally and specifically given for the reference platform (i.e.
NetBSD).

-Jan


------------------------------

_______________________________________________
cs631apue mailing list
cs631apue at lists.stevens.edu
https://lists.stevens.edu/mailman/listinfo/cs631apue


End of cs631apue Digest, Vol 36, Issue 2
****************************************


More information about the cs631apue mailing list